REFind()

Uses a regular expression (RE) to search a string for a pattern.

The search is case sensitive.

REFind( reg_expression=string, string=string, start=number, returnSubExpressions=boolean, scope=string, multiline=boolean );

Returns: any

Argument Description Default
reg_expression
string, required

Regular expression for which to search. Case sensitive.

string
string, required

String in which to search.

start
number, optional

A positive integer. Position in the string at which to start search. The default value is 1.

1

returnSubExpressions
boolean, optional

Default: false, If set true means returns the result as a struct with keys pos, match and len.

Each are an array with elements for the position and length of the match (first element), and the position and length of any matched subexpressions in the subsequent elements.

scope
string, optional

One: (Default)Returns the first value that matches the regex

All: Returns all values that match the regex

multiline
boolean, optional

If true indicate the regular expression should treat input as having multiple lines. This option affects the interpretation of the ^ and $ metacharacters. When true the ^ metacharacter matches at the beginning of every line, and the $ metacharacter matches at the end of every line. Additionally the . metacharacter will not match newlines when true.

Introduced: 5.3.8.23

false

Examples

writeDump(REFind("a+c+", "abcaaccdd"));
	writeDump(REFind("a+c*", "Abcaaccdd"));
	writeDump(REFind("['[:upper:]']", "abcaacCDD"));
	writeDump(REFind("[\?&]rep = ", "report.cfm?rep = 1234&u = 5"));
<span class="nv">teststring1</span> <span class="o">=</span> <span class="s2">&quot;The cat in the hat hat came back!&quot;</span><span class="p">;</span>
<span class="nv">st1</span> <span class="o">=</span> <span class="nf">REFind</span><span class="p">(</span><span class="s2">&quot;([&#39;[:alpha:]&#39;]+)[ ]+(\1)&quot;</span><span class="p">,</span><span class="nv">teststring1</span><span class="p">,</span><span class="m">1</span><span class="p">,</span><span class="s2">&quot;TRUE&quot;</span><span class="p">);</span>
<span class="nf">writeDump</span><span class="p">(</span><span class="nv">st1</span><span class="p">[</span><span class="s1">&#39;len&#39;</span><span class="p">][</span><span class="m">3</span><span class="p">]);</span>
<span class="nv">teststring2</span> <span class="o">=</span> <span class="s2">&quot;AAAXAAAA&quot;</span><span class="p">;</span>
<span class="nv">st2</span> <span class="o">=</span> <span class="nf">REFind</span><span class="p">(</span><span class="s2">&quot;x&quot;</span><span class="p">,</span><span class="nv">teststring2</span><span class="p">,</span><span class="m">1</span><span class="p">,</span><span class="s2">&quot;TRUE&quot;</span><span class="p">);</span>
<span class="nf">writeDump</span><span class="p">(</span><span class="nf">arrayLen</span><span class="p">(</span><span class="nv">st2</span><span class="p">[</span><span class="s1">&#39;pos&#39;</span><span class="p">]));</span>

See also