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