Match uppercase and lowercase letters from RegExp

I wrote some RegExp pattren as follows:

SomeText 

But I want pattren to match:

 Sometext sOMeTeXt SOMETEXT SoMEteXt 

Something like!

I actually want to use this

 \s?[^a-zA-Z0-9\_]SomeText[^a-zA-Z0-9\_] 

what should I do?

+6
regex case-insensitive
source share
4 answers

In many regular expression implementations, you can specify modifiers that apply to a specific 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 placed in case insensitive mode. According to this comparison table , this is supported if you use .net, Java, Perl, PCRE, Ruby or the JGsoft engine.

Of course, since you specify both az and az in your character classes, you can simplify and use case insensitive modifiers throughout the pattern:

 /\s?[^a-z0-9\_]sometext[^a-z0-9\_]/i 
+6
source share

use ignore modifier modifier

 /sometext/i 
+7
source share

If you cannot use modifiers:

 [Ss][Oo][Mm][Ee][Tt][Ee][Xx][Tt] 
+7
source share

Javascript: works both capital and small letters in any order.

 value.match(new RegExp(searchkey, "i")) 
0
source share

All Articles