-1

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?

St.Antario
  • 26,175
  • 41
  • 130
  • 318

2 Answers2

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,938
  • 5
  • 52
  • 68
1

You can use the case insensitive flag:

(?i).*unknow.*user.*
Florent Bayle
  • 11,520
  • 4
  • 34
  • 47