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
Daniel Vandersluis
source share