Why is this false in Java?
Pattern.matches("\\A[/0-9]","2 z CEA|B2 z E^")
edit:
I tried: (so that I can also catch new lines)
Pattern.matches("\\A[/0-9][.\\s]*?","2 z\n CEA|B2 z E^)
but it doesn’t work. How can I catch something like this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The problem is that
.matches()compares against the entire string, so the pattern must match it. Try this:The
.*?allows for more stuff to be at the end of the line. Using*?for the quantifier makes it select the minimum amount of characters.