my $search = "Sony's";
my $string = "in TV sony's walkman";
如何使用正则表达式在sony's
中获得“$string
”匹配。
答案 0 :(得分:6)
my $search = "Sony's";
my $string = "in TV sony's walkman";
$string =~ /$search/; # does not match
$string =~ /$search/i; # matches case-insensitive
这是一个初学者问题。请先learn the language,read a book or two。
答案 1 :(得分:3)
由于您需要不区分大小写的匹配项,请使用i
修饰符:
#!/usr/bin/env perl
use strict;
use warnings;
my $search = "Sony's";
my $string = "in TV sony's walkman";
if ( my ($match) = $string =~ /($search)/i ) {
print "Matched string: $match";
}
请阅读:perldoc perlretut
。