By default Java's .
does not match newlines. To have .
include newlines, set the Pattern.DOTALL
flag with (?s)
:
System.out.println(data1.matches("(?s).*London.*"));
Note for those coming from other regex flavors, the Java documentation use of the term "match" is different from other languages. What is meant is Java's string::matches()
returns true only if the entire string is matched, i.e. it behaves as if a ^
and $
were added to the head and tail of the passed regex, NOT simply that it contains a match.