I've seen lots of examples of making an entire regular expression case-insensitive. What I'm wondering about is having just part of the expression be case-insensitive.
For example, let's say I have a string like this:
fooFOOfOoFoOBARBARbarbarbAr
What if I want to match all occurrences of "foo" regardless of case but I only want to match the upper-case "BAR"s?
The ideal solution would be something that works across regex flavors but I'm interested in hearing language-specific ones as well (Thanks Espo)
Edit
The link Espo provided was very helpful. There's a good example in there about turning modifiers on and off within the expression.
For my contrived example, I can do something like this:
(?i)foo*(?-i)|BAR
which makes the match case-insensitive for just the foo portion of the match.
That seemed to work in most regex implementations except Javascript, Python, and a few others (as Espo mentioned).
The big ones that I was wondering about (Perl, PHP, .NET) all support inline mode changes.
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…