Perl : Quantifier follows nothing in regex; marked by

在用Perl替换字符串的时候出现的错误,这里是考察我们英文的时候了!Quantifier意思是量词。 原因我们使用了变量来作为匹配模式字符串,而这个字符串里面含有量词,导致识别出错。 怎么解决呢? 其实这里我们完全可以不用正则替换,而仅仅用字符串替换函数。 可惜Perl似乎没有字符串替换函数! 还好,找到\Q \E包住字符串 例子: [pl]#如果模式字符串采用变量的方法,而变量里面出现了量词,则会出现错误 sub testQuantityError { my $str = "he*llo"; my $match = "e*" ; #$match =~ s/\*/\\*/ ;之前的做法,把量词替换了,但这样会改变源字符串,不行 if( $str =~ m/\Q$match\E/ ) { print "match"; } }[/pl]