MATCH(<subject>,<pattern>,[&target],[group],[default])
- Category
- Calculations
- Added in
- v0.8.6
Runs a regular expression match on the <subject>
and puts the result in <&target>
.
Returns the matched groups as an array.
Alternative Syntax;
MATCH(<subject>,<pattern>,{&target1,&target2,&target3})
MATCH(<subject>,<pattern>,&target[])
Example
&input = "Hello World!!"
®ex = "(Hello) (World)"
MATCH(%&input%,%®ex%,&match)
// &match now contains the whole match "Hello World"
MATCH(%&input%,%®ex%,&match,2)
// &match now contains only the second group "World"
MATCH("no match",%®ex%,&match,1,"default")
// &match now contains the default value "default", since the regex couldn't match the input
MATCH(%&input%,%®ex%,{&hello,&world})
// &hello and &world now contain the first and second group
&groups[] = MATCH(%&input%,%®ex%)
// &groups[] now contains the whole match and the two groups
See also
- Regular Expressions QuickStart (www.regular-expressions.info)
- Online regex tester (regex101.com)
- Regex Reference and Tester (regexr.com)