MATCH
MATCH(<subject>,<pattern>,[&target],[group],[default])
Type: Action
Category: Calculations
Permission: N/A
Since Minecraft Version: v1.2.4
Since Version: v0.8.6
Minor: 8
API: N/A
Patch: 6
Description
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
Useful Links
Changelog
- Added em v0.8.6:
- Updated em v0.9: Can now store mutliple matches in multiple variables
- Updated em v0.8.7: New fifth parameter to specify default value if the match fails