Sunday, August 5, 2012
Groovy Patterns - I just forget!
http://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html
def thePattern = /foo/
def theString = "boo foo";
def theMatcher = theString=~thePattern
//1.
//it's "true" if it has at least one match,
if( theString =~ thePattern){
println "true";
}else{
println "false"
}
//2.
//print the the matcher to see
println theMatcher;
//note theMatcher is an array
println theMatcher[0];
//3
def stringToMatch = '''abc quick brownfox ? blah blah'''
def myPattern = /blah/
def m = stringToMatch=~myPattern
println m[0] + m.size()
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment