I have a body of text and I am trying to find a character sequence within it. String.contains()
will not work so Im trying to use String.matches
method and a regular expression. My current regex isn't working. Here are my attempts:
"1stline\r\n2ndline".matches("(?im)^1stline$");
// returns false; I expect true
"1stline\r\n2ndline".matches("(?im)^1stline$")
// returns false
"1stline\r\n2ndline\r\n3rdline".matches("(?im)^2ndline$")
"1stline\n2ndline\n3rdline".matches("(?im)^2ndline$")
"1stline\n2ndline\n3rdline".matches("(?id)^2ndline$")
How should i format my regex so that it returns true?