Skip to content

Latest commit

 

History

History
60 lines (27 loc) · 789 Bytes

groovy-regex.org

File metadata and controls

60 lines (27 loc) · 789 Bytes

There are five kinds of strings in groovy

Pattern myRegex = ~/regex/



Matcher myMatcher = 'subject' =~ /regex/

Matcher myMatcher = Pattern.compile(/regex/).matcher("subject")


\b is word boundary

def shoutedWord = ~/\b[A-Z]+\b/

def matcher = ("EUREKA" =~ shoutedWord)

assert matcher.matches()

def numberMatches = "1234" =~ /\d+/

assert numberMatches.matches()

This is another useful operator

==~

assert "1234" ==~ /\d+/

assert "FOO" ==~ /\d+/
 

cat text.txt| groovyclient -np -e "line.replaceAll("\a","\A")"

gvcl -pi -e 'line.replaceAll("A","a")' 4.txt

COUNT and LINE variables are available for `groovy -e ` script options