新博客http://www.cnblogs.com/zhjh256 欢迎访问
分类:
2009-04-19 14:18:33
# perl正则表达式之a, but not b,and vice versa
C:\Documents and Settings\Administrator>perl
$a="YES ";
print "1:$a\n" if $a=~ /(?=^(?:(?!YES).)*)NO/s;
$a="NO ";
print "2:$a\n" if $a=~ /(?=^(?:(?!YES).)*)NO/s;
$a="NO YES";
print "3:$a\n" if $a=~ /(?=^(?:(?!YES).)*)NO/s;
$a="YES NO ";
print "4:$a\n" if $a=~ /(?=^(?:(?!YES).)*)NO/s;
^D
2:NO
3:NO YES
C:\Documents and Settings\Administrator>perl
$a="oh NO,shit";
if ($a=~ /[^YES].*NO/)
{
print $a;
}
^D
oh NO,shit
C:\Documents and Settings\Administrator>perl
$a="oh NO,shit";
print $a if$a=~ /[^YES].*NO/;
^D
oh NO,shit