March 2019
Intermediate to advanced
242 pages
6h 21m
English
This section will provide another example of escaping sequence hell—defining regex patterns as Java strings.
To remove whitespaces (spaces or tabs) between a word character and a period (.), you'll need the following regex (regular expression) pattern:
(\w)(\s+))[\.]
To store it using a Java string, you'll need the following code:
String patternToMatch = "(\\w)(\\s+)([\\.,])"; // Isn't that a lot // to digest?
// Does the regex // pattern has
// a single // backslash, or, // two of them?
I'll share a quick secret here—when I started working with Java, one of my biggest nightmares was defining patterns as string values. I admit it; I had a difficulty writing patterns, and using the \ escape character ...
Read now
Unlock full access