How to match in a case-insensetive way in Java? I mean I want to write a regex like .*unknow.*user.*. But I wanna match unknow user as well as UnKnow UsER and so forth. What is the easiest way to do that in Java?
Asked
Active
Viewed 275 times
-1
St.Antario
- 24,791
- 31
- 112
- 278
-
You can also add `(?i)` at the beginning, as here: http://stackoverflow.com/questions/3436118/is-java-regex-case-insensitive – Javi Jan 19 '15 at 13:29
-
or write like `[uU][nN]...` – Avinash Raj Jan 19 '15 at 13:32
2 Answers
1
If you use Pattern, you can do it like this Pattern p = Pattern.compile("YOUR_REGEX", Pattern.CASE_INSENSITIVE);
Check out this blog for more info.
Predrag Maric
- 23,034
- 4
- 49
- 65