10, regular expression
l Groovy supports the regular expression represented by ~ "...", and also supports "= ~" operator (create matcher)
Import java.util.regex.matcher
Import java.util.regex.pattern
// Same as assert ("cheesecheese" = ~ "cheese"). Find ()
Assert "cheesecheese" = ~ "cheese"
// lets create a regex pattern
Pattern = ~ "a * b"
Assert Pattern InstanceOf Pattern
Assert Pattern.matcher ("AAAAB"). matches ()
// lets crete a matcher
Matcher = "cheesecheese" = ~ "cheese"
Assert Matcher InstanceOf Matcher
Answer = matcher.replaceAll ("EDAM")
askERT ANSWER == "EDAMEDAM"
l Matcher defaults will call the Find () method to return to the Boolean value, so you can use = ~ to keep the simple use of the = ~ operator.
l The example of the above mode is mainly to demonstrate the use of pattern, which can actually simplify
Assert ("AAAAB" = ~ "a * b"). matches ()