-1

我需要确定是否

+review CR @someuser

存在于字符串中。我怎样才能做到这一点?

4

2 回答 2

2

您将需要转义元字符并使用匹配的正则表达式m//

if ($string =~ /\+review CR \@someuser/) {
    # do something
}

请注意,您不能使用\Q ... \E转义序列来转义元字符,因为@someuser仍会被插值。您可以将其用于+,但您仍然需要转义@,因此这种方式更简单。您也可以使用该quotemeta功能。但是,在这种情况下,这可能是矫枉过正。

阅读更多关于此的内容perldoc perlop

于 2013-02-28T23:04:03.033 回答
1

Use index:

$search_string = "+review CR \@someuser";
if (index($string, $search_string) != -1) { # found }

Or, if you use a regex, you'll want to make sure the '+' and '@' are properly escaped:

if ( $string =~ m#\+review CR \@someuser# ) { # found }

于 2013-02-28T23:06:05.493 回答