views:

51

answers:

3

Hi . 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 ?

+1  A: 

use ignore case modifier

/sometext/i
KARASZI István
Thanks .. This answer does not work for me
Ahmad Alshaikh
A: 

In case you cannot use modifiers:

[Ss][Oo][Mm][Ee][Tt][Ee][Xx][Tt]
Gumbo
Good idea . thanks
Ahmad Alshaikh
A: 

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
Daniel Vandersluis
Amazing .. Thank you very much
Ahmad Alshaikh