RegEx Matches
Description
Find matches (occurrences) of a RegEx pattern in a string.
Snippet
import:
java.util.regex.Pattern
java.util.regex.Matcher
expression [group[s] %integers% in] match[es] [of] %text% in %text%:
get:
set {_p} to Pattern.compile(expr-2)
set {_matcher} to {_p}.matcher(expr-3)
while {_matcher}.find():
while {_matcher}.group({_group} ? 0) is set:
add {_matcher}.group({_group} ? 0) to {_matches::*} if exprs-1 ? 1 contains {_group} ? 0
add 1 to {_group}
return {_matches::*}
Applications
I want to find out what mob is being summoned in a summon command. I will use the following pattern to retrieve the mob that was summoned: /summon (.+?)\s?
. The summoned mob is stored in group 1.
broadcast (group 1 in match "/summon (.+?)\s?" in "/summon minecraft:ender_dragon")
The output would be minecraft:ender_dragon
.
Last updated
Was this helpful?