FINDFIRST Function

Searches the specified string for a pattern match using an already compiled regular expression.

Category: Regular Expression
Returned data type: Integer

Syntax

r.FINDFIRST(input)

Required Argument

input

specifies the string value in which you want to search for the pattern defined by your compiled regular expression. This can be an explicit string ("MyValue"). This can also be a variable already defined in your expression code or passed to the expression node as a column from a previous node (MyValue or "My Value").

  Requirement input must not be NULL or blank.

Details

The FINDFIRST function indicates if one or more pattern matches were found in the input. This function can be used to enter a logical loop that pulls out a series of matched patterns from an input string. A false value indicates that no match is found and that processing can continue.

Examples

The following statements illustrate the findfirst regex function:

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, turn this setting off and remove the SETEOF() function. Unless stated otherwise, all code shown should be entered in the Expression tab of the Expression node.

//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]")

// If a pattern match is found this will evaluate to 1 (TRUE)

if r.findfirst("Abc")

// Print the output to the statistics file. You must run

// this job for stats to be written. A preview will not generate

// a message in the log.

print("Found match starting at " & r.matchstart() & " length " & r.matchlength())

// Terminate the expression node processing

seteof()