regexp case sensitive / ignore case based on a variable
regexp case sensitive / ignore case based on a variable
am 24.10.2005 09:40:39 von Pierre-Yves
Hello,
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";
}
Thank you,
Pierre.
Re: regexp case sensitive / ignore case based on a variable
am 24.10.2005 10:06:54 von someone
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
Re: regexp case sensitive / ignore case based on a variable
am 24.10.2005 10:07:22 von Joe Smith
Pierre wrote:
> Hello,
>
> I would like to write a regexp that can be either case sensitive or not
$flag = $case_sensitive ? '(?-i)' : '(?i-)';
if ($string =~ /${flag}${pattern}/) {print "Got it!";}
-Joe
Re: regexp case sensitive / ignore case based on a variable
am 24.10.2005 10:20:20 von Pierre-Yves
Wonderful!
Thank you all !!!
"Joe Smith" wrote in message
news:--ydnb7yl8yiC8HeRVn-iw@comcast.com...
> Pierre wrote:
> > Hello,
> >
> > I would like to write a regexp that can be either case sensitive or not
>
> $flag = $case_sensitive ? '(?-i)' : '(?i-)';
> if ($string =~ /${flag}${pattern}/) {print "Got it!";}
>
> -Joe
Re: regexp case sensitive / ignore case based on a variable
am 24.10.2005 13:48:49 von Pierre-Yves
Hello,
One more question...
when I have a string with accents and "ignore case" is set, it doesn't
work...
why? how can I make this work ?
i.e:
$string = "c'est l'été!";
$pattern = "été";
Can anyone help please ?
"Joe Smith" wrote in message
news:--ydnb7yl8yiC8HeRVn-iw@comcast.com...
> Pierre wrote:
> > Hello,
> >
> > I would like to write a regexp that can be either case sensitive or not
>
> $flag = $case_sensitive ? '(?-i)' : '(?i-)';
> if ($string =~ /${flag}${pattern}/) {print "Got it!";}
>
> -Joe
Re: regexp case sensitive / ignore case based on a variable
am 24.10.2005 14:13:21 von Matt Garrish
"Pierre" wrote in message
news:435ccb18$0$10953$ba620e4c@news.skynet.be...
> Hello,
>
> One more question...
> when I have a string with accents and "ignore case" is set, it doesn't
> work...
> why? how can I make this work ?
>
> i.e:
> $string = "c'est l'été!";
> $pattern = "été";
>
> Can anyone help please ?
Try adding the following to your script:
use locale;
Matt