match() checks if the String input includes a regular_expression and returns the result.
regular_expression can be either a String or a Pattern object of a particular regex API. The syntax of regular expression depends on the regex API.
match("a*b", "aaaaabbb") => true
options is a string of the following characters.
option meaning i Case-insensitive pattern matching m Treats string as multiple lines s Treats string as single line. "." matches any single character n Meta characters are escaped. other Passed to a particular Regex API
match("a", "ABC", "i") => true
getMatch(0) returns the previously matched string. getMatch(n) returns the string that matches the Nth regex group.
match("(a*)b(c*)", "aaabcc") => true
getMatch(0) => "aaabcc"
getMatch(1) => "aaa"
getMatch(2) => "cc"
getMatches() returns an array of matched string with pattern groups.
match("(a*)b(c*)", "aaabcc") => true
getMatches() => ["aaa", "cc"]
getMatchStart(0) returns the start index of previously matched string. getMatchStart(n) returns the start index of string that matches the Nth regex group.
match("(a*)b(c*)", "aaabcc") => true
getMatchStart(0) => 0
getMatchStart(1) => 0
getMatchStart(2) => 4
getMatchEnd(0) returns the end index of previously matched string. getMatchEnd(n) returns the end index of string that matches the Nth regex group.
match("(a*)b(c*)", "aaabcc") => true
getMatchEnd(0) => 6
getMatchEnd(1) => 3
getMatchEnd(2) => 6
getNumberOfGroups() returns the number of parenthesized subexpressions available after a successful match.
The result of this function is undefined if it is called after a unsuccessful match.
formatMatch() formats the replacement_string, substituting captured subsequences of the previous pattern match.
match("(a+)(b+)", "aaaabbbb")
formatMatch("$2$1")
=> "bbbbaaaa"
If func is specified, matchAll() searches the regular_expression in input and calls func passing the matched words in turn, then returns the number of matches.
If func is not specified, it returns an Iterator that can be used to get the matched words.
for (word : matchAll("[a-z]+", "abc def")){
println(word)
}
When a string is specified as the 2nd parameter, substitute() replaces the string which matches the regular_expression with replacement. When 'n' is included in options, meta characters in replacement, if any, have no effect.
When a function is specified as the 2nd parameter, substitute() replaces the string which matches the regular_expression with the result of the function call. The function must be able to take zero or one argument. If the function takes one argument, matched word is passed as the argument.
regular_expression can be either a String or a Pattern object of a particular regex API. The syntax of regular expression depends on the regex API.
substitute("[a-zA-Z]+", {x-> toUpperCase(x)}, "aBcDe") => "ABCDE"
split() tokenizes a string with the regular_expression as the delimiter. It returns a java.util.List object which contains the resulting tokens.
regular_expression can be either a String or a Pattern object of a particular regex API. The syntax of regular expression depends on the regex API.
split(`\.`, "a.b.c") => ["a", "b", "c"]
whichRegexAPI() returns the module name which is currently used. It returs null if no scripts is loaded.
getMatchCount() returns the number of substitution done by previous substitute() call.
regex() makes a Pattern object of a particular regex API from expression. For example, when using pnuts.regex.jsr51 module, it returns a java.util.regex.Pattern object.