wtd
|
Posted: Tue Nov 16, 2004 11:45 pm Post subject: [Regex-tut] Case insensitivity and local modifiers |
|
|
Quick recap
In previous tutorials I used a set to achieve case insensitivity at the beginning on a word.
It works, but...
This works, and it's even fairly concise, but, it doesn't really indicate that case insensitivity was my goal. It also gets messier if, for instance, I wanted to make the entire word "hello" case-insensitive.
code: | /[hH][eE][lL][lL][oO]/ |
There's a better way?
Yes, there is. The "i" modifier can make the entire regular expression case-insensitive. It's applied in the same way as the m and x modifiers.
Back to the future
Going back to the original example, we want only the first letter of "hello" to be case-insensitive. Fortunately, we can apply modifiers locally.
Similarly, modifiers can be negated locally. A rather odd reversal of the above might look like:
These two styles can be mixed.
|
|
|