Function RegexSearch(SearchString, Pattern[, CaseSensitive])

RegexSearch

The function RegexSearch tells if there is a substring in the search string that matches the regex pattern.

RegexSearch(
     SearchString,    ! (input) a scalar string expression
     Pattern,         ! (input) a scalar string expression
     [CaseSensitive]  ! (optional) binary
     )

Arguments

SearchString

The string in which you want to find a substring matching the regex pattern.

Pattern

The regular expressions pattern to match. Multilines are not supported.

CaseSensitive (optional)

The search will be case sensitive when the value is 1. The default depends on the setting of the option Case_sensitive_string_comparison, and is 1 if this option is ‘On’ and 0 if this option is ‘Off’. The default of the option Case_sensitive_string_comparison is ‘On’.

Note

Return Value

The function returns 1 if a substring that matches the regex pattern exists in the search string. When the pattern is an empty string, the function returns 1. In all other cases, the function returns 0.

Example

The following example checks if the path contains the specified folder name on disk C. With the following declarations (and initial data):

Parameter P;
StringParameter path {
    InitialData: "C:\\ProgramFiles\\Folder\\SubFolder";
}
StringParameter regexPattern {
    InitialData: "c:.*\\\\ProgramFiles(\\\\|$)";
}

the statement

P := regexsearch(path, regexPattern, 0);

results in P being 1.

The used regular expression pattern specifies that the path starts with c:, followed by zero or more characters (regular expression: .*), followed by \ProgramFiles (regular expression: \\\\ProgramFiles), and ends with a backslash or the end of a line (regular expression: (\\\\|$)).

See also

The functions FindString, FindNthString.