I’m trying to match a string, starting with a dot using java’s matches method. Why this doesn’t work:
".why?".matches("\\.*");
When I use a single slash, i’m getting an error for invalid escape sequence.
Thanks in advance
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.
"\\.*"matches a string consisting of zero or more'.'s. It matches the following (quoted) strings:(and so on)
You want:
"\\..*"instead. Note that.by default does not match line breaks, so it wouldn’t match the following string:For such string to be matched, you need to enable DOT-ALL:
"(?s)\\..*"