-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
  • 24,791
  • 31
  • 112
  • 278

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,034
  • 4
  • 49
  • 65
1

You can use the case insensitive flag:

(?i).*unknow.*user.*
Florent Bayle
  • 10,752
  • 4
  • 33
  • 44