Groovy Regex
Open Source Your Knowledge, Become a Contributor
Technology knowledge has to be shared and made accessible for free. Join the movement.
Groovy Regex!
This template is created to help you learn different usage of regex in Groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
//lets see how to use regex in groovy
//==~ is the pattern matcher
//results in java.util.regex.Matcher instance
def finder = ('groovy' =~ /gr.*/)
println finder instanceof java.util.regex.Matcher
def matcher = ('groovy' ==~ /gr.*/)
println matcher instanceof Boolean
println !('Groovy rocks!' ==~ /Groovy/) // ==~ looks for an exact match.
println 'Groovy rocks!' ==~ /Groovy.*/
// Groovy matcher syntax can be used in other methods.
println (['abc'] == ['def', 'abc', '123'].findAll { it =~ /abc/ })
println ([false, false, true] == ['def', 'abc', '123'].collect { it ==~ /\d{4}/ })
Enter to Rename, Shift+Enter to Preview
Open Source Your Knowledge: become a Contributor and help others learn. Create New Content