Regular Expression Find - < regex_find >() ... [Pro]
Variable Regular Expression Find <regex_find>("Input text/variable","Pattern","Start index",Variable for match,Variable for index,Variable for size) Available in: Professional edition
|
This command searches in the input text for a matching regular expression pattern. The command searches from the position passed as "Start index". If a match is found then the matching substring, index where it is located in the input text, and its length is returned.
|
#
|
Parameter name
|
Parameter description
|
1
|
Input text/variable
|
Input text.
|
2
|
Pattern
|
Regular expression pattern.
|
3
|
Start index
|
Index (position) in the text where to start searching. 0 means that the input text is searched from beginning.
|
4
|
Variable for match
|
Name of the variable that will receive substring that matches the regular expression pattern. If no match is found then this variable will contain empty string (equal to %_vStrEmpty%).
|
5
|
Variable for index
|
Name of the variable that will receive index (position) in the input text where the match was found. If no match is found then this variable will contain -1.
|
6
|
Variable for size
|
Name of the variable that will receive the length of the matching substring found. If no match is found then this variable will contain 0.
|
|
|
Example (Macro Steps):
|
1
|
<#> <#>This example shows how to find an e-mail addresses in input text
|
2
|
Macro execution: ONLY COMMANDS
|
3
|
Variable SET "vSearchFrom=0", Message text=""
|
4
|
Repeat steps UNTIL "1" (Counter variable initial value = "", Counter loop increment = "")
|
5
|
Variable Regular Expression Find Pattern "\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}" in "This is a text that contains e-mail addresses such as john.a.smith@comp-comp-company.com or FredieX@dot.dot.TV or other...." (Start index=%vSearchFrom%, Variable for match = vM, Variable for index = vI, Variable for size = vS)
|
6
|
IF %vM%==%_vStrEmpty%
|
7
|
Message SHOW "Information" : "No more e-mail addresses found." (other parameters: x = -100, y = -100, Window title = , Buttons = OK, Timeout (seconds) = 0, Always on top = No).
|
8
|
Repeat steps BREAK
|
9
|
ELSE activate
|
10
|
Message SHOW "Information" : "E-mail found: %vM% Position in text: %vI% Length: %vS%" (other parameters: x = -100, y = -100, Window title = , Buttons = OK, Timeout (seconds) = 0, Always on top = No).
|
11
|
Variable SET "%vSearchFrom%=EXPR(%vI%+%vS%)", Message text=""
|
12
|
ENDIF
|
13
|
Repeat steps END
|
|
Example (Plain Text):
<#>This example shows how to find an e-mail addresses in input text
<cmds>>
<varset>("vSearchFrom=0","")
<for>("","1","")
<regex_find>("This is a text that contains e-mail addresses such as john.a.smith@comp-comp-company.com or FredieX@dot.dot.TV or other....","\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}","%vSearchFrom%",vM,vI,vS)
<if>("%vM%==%_vStrEmpty%")
<msg>(-100,-100,"No more e-mail addresses found.","",1,0,0,0)
<for_break>
<else>
<msg>(-100,-100,"E-mail found: %vM%
Position in text: %vI%
Length: %vS%","",1,0,0,0)
<varset>("%vSearchFrom%=EXPR(%vI%+%vS%)","")
<endif>
<for_end>