-1

I need to workout a way to test a string contains some words or not, doesn't matter uppercase or lowercase. E.g

String ppe1 = "Mask"
String ppe2 = "mask"
String ppe3 = "MASK"

then when I do

return ppe1.matches("[A-Za-z]*mask")  // it should return true

or

return ppe2.matches("[A-Za-z]*mask")  // it should return true

or

return ppe3.matches("[A-Za-z]*mask")  // it should return true

I know above regex is totally wrong,, but just wish to demo my idea for what I need, In a simple word, as long as string contains term 'Mask' , doesn't matter 'MASK' or 'mask' or 'mASk' or 'masK' or whatever combo, regex should detect the term and always return true. Please suggest with code example. Thanks

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
sefirosu
  • 2,558
  • 7
  • 44
  • 69

1 Answers1

1

An arguably easier approach would be to force the case and then use contains:

return myString.toLowerCase().contains("mask");
Mureinik
  • 297,002
  • 52
  • 306
  • 350