1

i have following

Pattern loPattern = Pattern.compile(someText.toLowerCase(), Pattern.CASE_INSENSITIVE | Pattern.DOTALL);

this line throws exception if someText has pattern like e[l

this someText can contain characters [a-z][A-Z][0-9]!@#$%^&;*()_+=|{}[];:'"<>;,.?/`~§ -

whats the possible solution for it?

2
  • Could you post SSCCE? Commented Oct 21, 2013 at 12:49
  • 1
    It really does not make sense to lowercase the pattern and match case insensitive. Commented Oct 21, 2013 at 13:59

1 Answer 1

6

Add the Pattern.LITERAL flag so the meta-characters are not translated in the expression

Pattern loPattern = 
    Pattern.compile(someText, 
       Pattern.CASE_INSENSITIVE | Pattern.DOTALL | Pattern.LITERAL);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.