July 2013
Intermediate to advanced
370 pages
8h 27m
English
The JDK package java.util.regex contains the API for pattern-matching with regular
expressions (RegEx). For a detailed discussion of RegEx, refer to Jeffrey Friedl’s Mastering Regular Expressions [Fri97].
String’s
replaceFirst
and
replaceAll
methods,
among other methods, make good use of RegEx pattern-matching. Groovy adds operators and symbols to make it easier to program
with RegEx.
Groovy provides the operator ~ to easily create a RegEx pattern. This operator maps to
String’s
negate
method:
| WorkingWithStrings/RegEx.groovy | |
| | obj = ~"hello" |
| | println obj.getClass().name |
The output shows the type of the instance created:
| | java.util.regex.Pattern |
The previous example shows that ~ applied to String
Read now
Unlock full access