Find (=~) operator is used to get an instance of java.util.regex.Matcher.
HelloWorld.groovy
def text = "aaaab" def matcher = text =~ /a*b/ matcher.matches() println "I found the text " + matcher.group() println "Starting at index " + matcher.start() println "Ending at index " + matcher.end()
Output
I found the text aaab Starting at index 0 Ending at index 4
def matcher = text =~
/a*b/
=~ creates a matcher against the text variable, using the
pattern on the right-hand side. Return type of =~ is a Matcher
No comments:
Post a Comment