For Programmers: Free Programming Magazines  


Home > Archive > PERL Programming > October 2005 > Re: regexp case sensitive / ignore case based on a variable









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: regexp case sensitive / ignore case based on a variable
John W. Krahn

2005-10-24, 3:55 am

Pierre wrote:
>
> I would like to write a regexp that can be either case sensitive or that can
> ignore the case based on a variable (value would be either 'i' or '').
> For instance in the below code the variable is $case.
> I can't make that piece of code working fine. Anyone can help please ?
>
> my $str = "Hello World!";
> my $pattern "hello";
> my $case = "i";
>
> if ($str =~ s/${pattern}/${case}) {
> print "match!\n";
> }


if ( $str =~ /(?$case:$pattern)/ ) {
print "match!\n";
}



John
--
use Perl;
program
fulfillment
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com