4D v16.3

Match regex

Home

 
4D v16.3
Match regex

Match regex 


 

Match regex ( pattern ; aString ; start {; pos_found ; length_found}{; *} ) -> Function result 
Parameter Type   Description
pattern  Text in Regular expression
aString  Text in String in which search will be done
start  Longint in Position in aString where search will start
pos_found  Longint array, Longint variable in Position of occurrence
length_found  Longint array, Longint variable in Length of occurrence
Operator in If passed: only searches at position indicated
Function result  Boolean in True = search has found an occurrence; Otherwise, False.
Match regex ( pattern ; aString ) -> Function result 
Parameter Type   Description
pattern  Text in Regular expression (complete equality)
aString  Text in String in which search will be done
Function result  Boolean in True = search has found an occurrence; Otherwise, False.

The Match regex command checks 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 where you want 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

Search for complete equality (simple syntax):
vfound:=Match regex(pattern;mytext)

 QUERY BY FORMULA([Employees];Match regex(".*smith.*";[Employees]name))

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))

Search with support of “capture groups” via parentheses. ( ) are used to specify groups in the regexes:
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

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.

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.

 
PROPERTIES 

Product: 4D
Theme: String
Number: 1019

This command modifies the Error system variableThis command can be run in preemptive processesThe Unicode mode affects this command

 
HISTORY 

Created: 4D v11 SQL

 
ARTICLE USAGE

4D Language Reference ( 4D v16)
4D Language Reference ( 4D v16.1)
4D Language Reference ( 4D v16.2)
4D Language Reference ( 4D v16.3)