July 2017
Intermediate to advanced
158 pages
3h 41m
English
Let's look at a few examples to understand some of these methods.
To compile a regular expression for decimal numbers, we can use the following code snippet:
final String decimalPattern = "^[+-]?\\d*\\.?\\d+$"; Final Pattern pattern = Pattern.compile(decimalPattern);
The static method, Pattern.compile, compiles a string regex and returns a Pattern instance.
To match text between ## and ## that may include newlines as well, we can use the following compiled pattern:
final String re = "##.*?##"; Final Pattern pattern = Pattern.compile(re, Pattern.DOTALL);
Here, we are using two parameters: the Pattern.compile method and passing DOTALL as a flag in the second parameter, since we want to match the newline ...
Read now
Unlock full access