I have a following piece of code:
String myString;
boolean myResult;
myString = "First\nSecond\nThird\nFourth";
myResult = myString.matches("First.*");
myResult = myString.matches(".*First.*");
myResult = myString.matches(".*Second.*");
myResult = myString.matches("First\nSecond\nThird\nFourth");
the last one returns true, all the rest are false…
I though all of the above expressions would return true. Also I need to find strings that start with “First”, I thought the first .matches() would cover it, but it does not. How should it look like?
The dot doesn’t by default match end-of-line chars, but if you prefix your regex string with (?s), then it will match them. This enables the DOTALL match flag.