Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How To Catch if in all possible case?

Tags:

java

regex

I wish to find a regex which matches all combination of the word if. So the valid ones are :

iF, IF , If and if

I have a regex here: [iIfF]*

Eventhough it is matching what I want, it is matching the word Fi and other such combinations too.

Where I'm making the mistake?

like image 739
sriram Avatar asked Jan 30 '26 08:01

sriram


2 Answers

Since you seem to be using Java, you'd want:

Pattern p = Pattern.compile("if", Pattern.CASE_INSENSITIVE);
like image 129
Peter C Avatar answered Feb 01 '26 23:02

Peter C


[iI][fF]

Everything in the brackets in any combination will be allowed.

EDIT Java allows for case insensitive RegEx

"(?i)if"

would suffice

like image 28
Louis Ricci Avatar answered Feb 01 '26 21:02

Louis Ricci