Pattern.quote(“pattern”) returns \Qpattern\E. Is it really necessary to literalize a string if there is no meta character in it?
Pattern.quote(pattern) returns \Qpattern\E . Is it really necessary to literalize a string if there
Share
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.
No, it’s not necessary, but that’s what the implementer chose to do, probably to simplify the implementation and because the cost of the unnecessary
\Qand\Eis rather small.In my JDK, the only thing that
Pattern.quote()cares about is whether there are already\Qand\Ein the pattern. It doesn’t look for any other special characters.