I want to add the option 'x' after my regex to ignore white space when using String.matches() in java. However, I see this on http://www.regular-expressions.info/java.html:
The Java String class has several methods that allow you to perform an operation using a regular expression on that string in a minimal amount of code. The downside is that you cannot specify options such as "case insensitive" or "dot matches newline".
Does anyone have an easy way around this using java, so that I don't have to change my regex to allow zero or more white space in every spot there could be white space?
An easy way is to use Pattern class instead of just using the matches() method.
For example:
Pattern ptn = Pattern.compile("[a-z]+", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE);
Matcher mtcher = ptn.matcher(myStr)
....
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With