I wrote some RegExp pattren like this :
SomeText
But I want the pattren to match with :
Sometext
sOMeTeXt
SOMETEXT
SoMEteXt
Somethings like that !
In fact I want to use this
\s?[^a-zA-Z0-9\_]SomeText[^a-zA-Z0-9\_]
what should i do ?
In many regex implementations, you can specify modifiers that apply to a given part of your pattern. Case-insensitivity is one of those modifiers:
\s?[^a-zA-Z0-9\_](?i)sometext(?-i)[^a-zA-Z0-9\_]
The section between (?i)
and (?-i)
will be put into case-insensitive mode. According to this comparison table, this is supported if you're using .net, Java, Perl, PCRE, Ruby or the JGsoft engine.
Of course, since you're specifying both a-z
and A-Z
in your character classes, you could simplify and use the case-insensitive modifier on the entire pattern:
/\s?[^a-z0-9\_]sometext[^a-z0-9\_]/i
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With