正则表达式匹配URL的问题

正则表达式匹配URL的问题

正则表达式匹配URL的问题
my $a = "1\tlove town\thttp://www.google.com\thttp://www.google.com/search?q=love town";
my $str = "http://www.google.com/search?q=love town";

if (($a =~ /$str/))
{
print "find \n";
}
else
{
print "nothing \n";
}

结果是nothing, 有没有人知道是什么原因?
变量匹配需要这样,改一下.
变量匹配需要这样,改一下: if (($a =~ /\Q$str\E/))
个人认为,正则不要滥用,.
个人认为,正则不要滥用,这种情况下,应该用 index 函数。
[quote]index STR,SUBSTR,POSITION
index STR,SUBSTR
The index function searches for one string within another, but
without the wildcard-like behavior of a full regular-expression
pattern match. It returns the position of the first occurrence
of SUBSTR in STR at or after POSITION. If POSITION is omitted,
starts searching from the beginning of the string. POSITION
before the beginning of the string or after its end is treated
as if it were the beginning or the end, respectively. POSITION
and the return value are based at 0 (or whatever you've set the
$[ variable to--but don't do that). If the substring is not
found, "index" returns one less than the base, ordinarily -1.[/quote]
[quote]回复给 smilelance.
[quote]回复给 smilelance : 变量匹配需要这样,改一下....[/quote]
可以用了,非常感谢smilelance!!!

[quote]回复给 flw : 个人认为,正则不要滥用,....[/quote]
同样感谢flw.