my ($INV_NB, $USAGE)=split /\|/,"9998|999999999999999";
if ($USAGE=~/^\d{15}\b/)
{
print "\nUSAGE is Valid\n";
print "length of $USAGE is ",length($USAGE);
}
这按预期工作,但我怎么能否定这个正则表达式呢?如果用法不是/^\d{15}\b/
if ($USAGE!=~/^\d{15}\b/)
{
print "\nUSAGE is Invalid\n";
print "length of $USAGE is ",length($USAGE);
}
我试过这个,但它没有用......
答案 0 :(得分:5)
答案 1 :(得分:4)
其他答案是正确的,但如果您想要否定正则表达式(而不是应用它的运算符),您可以使用
/^(?!.*?$regex_to_be_negated)/s
答案 2 :(得分:0)
此外:
unless ($USAGE=~/^\d{15}\b/)
{
print "\nUSAGE is Invalid\n";
print "length of $USAGE is ",length($USAGE);
}