[Melbourne-pm] case insensitive REs
wigs at stirfried.org
wigs at stirfried.org
Tue May 6 21:20:22 PDT 2008
On Wed, May 07, 2008 at 02:11:23PM +1000, Tim Connors wrote:
> I want the user to be able to supply a -i flag to my program to make
> global case insensitive searching.
>
> Except that when I actually go to perform the RE operation in perl, it
> only takes /i as a modifier. I can't simply say, where $case contains
> either "i" or "":
>
> while (/($re)/g$case) {
> ...
> }
You can include matching operators inside the regex; for example:
my $pattern = "(?i)foobar";
if ( /$pattern/ ) { }
This example is taken straight from perldoc perlre, under the 'Extended
Patterns' section.
Cheers,
--
Aaron
More information about the Melbourne-pm
mailing list