Returns the location of the last pattern match found.
Category: | Regular Expression |
Returned data type: | Integer |
r.MATCHSTART(input)
input
specifies a string value in which you want to search for the pattern defined by your compiled regular expression
Requirement | input must not be NULL or blank. |
The MATCHSTART function returns the starting character position of a substring that has been matched to the regular expression. NULL is returned if there is no substring currently under consideration and therefore no length to return. A logical loop can be used to iterate through all matching substrings. The MATCHLENGTH( ) function can be used in conjunction with MATCHSTART( ) to pull out matching substrings so that comparisons can be made to other values or to values stored in other variables.
Note: This example can be run in a stand-alone expression node if the Generate rows when no parent is specified option is selected. If passing data to this node instead, turn this setting off and remove the SETEOF() function. The PUSHROW statements are also unnecessary if passing data values in to the node as data rows. Unless stated otherwise, all code shown should be entered in the Expression tab of the Expression node.
// Define some string variables
string MyString
string MySubString
integer StartLocation
// Set one to some sample input
MyString = "00AA111BBB2222CCCC"
// Will hold the starting location of matched patterns
StartLocation = 0
//You must define a regex object
regex r
// Then compile your regular expression
// This one will match any single uppercase letter
r.compile("[A-Z]+")
// Find the first pattern match
if r.findfirst(MyString)
begin
// Pull the pattern from MyString and place it into MySubString
MySubString = mid(MyString, r.matchstart(),r.matchlength())
// Use pushrow to create new rows - this is purely for the sake of
// clarity in the example
pushrow()
// Create a while loop that continues to look for matches
while r.findnext(MyString)
begin
// Pull the pattern from MyString and place it into MySubString
again
MySubString = mid( MyString, r.matchstart(),r.matchlength())
// Set StartLocation to the starting point of each pattern found
StartLocation = r.matchstart()
// Just for display again
pushrow()
end
end
// Terminate the expression node processing
seteof(true)
// Prevent the last pushrow() from showing up twice
return false