3

具体的には、同等のものを達成する方法はありますか

my $string = 'this is some example text';
my $match = qr/foobar/;
print 'success' if $string !~ $match;

=〜のみを使用し、否定演算子を使用しない場合はどうなりますか?

具体的には、文字列が指定された値と一致しないことを確認する必要があります。テスト関数は正規表現オブジェクトを取得し、それらを値に積極的に適用します。 値は検索された文字列にまったく含まれていてはならず、先読みアサーションと後読みアサーションが複雑になります。

次のようなものが良いテストかもしれません:

my $string = 'this is some example text';
my $match =~ qr/foobar/;
# $negated_match contains $match, or some transformed variation of it
my $negated_match = qr/$YOUR_REGEX_HERE/; 
die 'failure' if $string =~ $match;
print 'success' if $string =~ $negated_match;

ルックアラウンドアサーションを使用してこれを行う方法があると思いますが、まだ戸惑っていません。Perl固有の回答は許容されます。

4

1 に答える 1

5
my $string = 'this is some example text';
my $match = qr/^(?!.*foobar)/s;
print 'success' if $string =~ $match;
于 2012-10-15T18:44:18.613 に答える