version 11
Match regex (pattern; aString{; start{; pos_found; length_found; *}}) Boolean
Parameter | Type | Description | |
pattern | Text | Regular expression | |
aString | Text | String in which search will be done | |
start | Number | Position in aString where search will start | |
pos_found | Longint Var | Longint Array | Position of occurrence | |
length_found | Longint Var | Longint Array | Length of occurrence | |
* | * | If passed: only searches at position indicated | |
Function result | Boolean | True = search has found an occurrence; | |
Otherwise, False. |
Description
The Match regex command can be used to check the conformity of a character string with respect to a set of synthesized rules by means of a meta-language called "regular expression" or "rational expression." The regex abbreviation is commonly used to indicate these types of notations.
Pass the regular expression to search for in pattern. This consists of a set of characters used for describing a character string, using special characters.
Pass the string in which to search for the regular expression in aString.
In start, pass the position at which to start the search in aString.
If pos_found and length_found are variables, the command returns the position and length of the occurrence in these variables. If you pass arrays, the command returns the position and length of the occurrence in the element zero of the arrays and the positions and lengths of the groups captured by the regular expression in the following elements.
The optional * parameter indicates, when it is passed, that the search must be carried out at the position specified by start without searching any further in the case of failure.
The command returns True if the search has found an occurrence.
For more information about regex, refer to the following address:
http://en.wikipedia.org/wiki/Regular_expression
For more information about the syntax of the regular expression passed in the pattern parameter, refer to the following address:
http://www.icu-project.org/userguide/regexp.html
Examples
This command can be used in several ways, as illustrated by the following examples:
1. Search for complete equality:
vfound:=Match regex(pattern;mytext)
QUERY BY FORMULA([Employees];Match regex(".*smith.*"; [Employees]name))
2. Search in text by position:
vfound:=Match regex( pattern;mytext; start; pos_found; length_found)
Example to display all the $1 tags:
start:=1 Repeat vfound:=Match regex("<.*>";$1;start;pos_found;length_found) If(vfound) ALERT(Substring($1;pos_found;length_found)) start:=pos_found+length_found End if Until(Not(vfound))
3. Search with support of "capture groups":
vfound:=Match regex( pattern;mytext; start; pos_found_array; length_found_array)
ARRAY LONGINT(pos_found_array;0) ARRAY LONGINT(length_found_array;0) vfound:=Match regex("(.*)stuff(.*)";$1;1;pos_found_array; length_found_array) If(vfound) $group1:=Substring($1;pos_found_array{1};length_found_array{1}) $group2:=Substring($1;pos_found_array{2};length_found_array{2}) End if
4. Search limiting the comparison of the pattern to the position indicated:
Add a star to the end of one of the two previous syntaxes.
vfound:=Match regex("a.b";"---a-b---";1;$pos_found;$length_found) `returns True vfound:=Match regex("a.b";"---a-b---";1;$pos_found;$length_found;*) `returns False vfound:=Match regex("a.b";"---a-b---";4;$pos_found;$length_found;*) `returns True
Note: The positions and lengths returned are only meaningful in Unicode mode or if the text being worked with is of the 7-bit ASCII type.
Error Handling
In the event of an error, the command generates an error that you can intercept via a method installed by the ON ERR CALL command.