2012-05-11 15 views
2
/\d/   # contains a digit 
/^\D*$/  # doesn't contain a digit 

/[abc]/  # contains either the letter a, b, or c 
/^[^abc]*$/ # doesn't contain a, b, or c 

/foo|bar/ # contains foo or bar 
/???????/ # doesn't contain foo or bar 

誰が私を助けることができますか?私は任意の解決策を見つけることができませんでしたが、プログラマブルロジックなしでを否定する正規表現が必要です。Perl正規表現/ foo | bar/negation

+2

|バー/' 'で/ fooの|バー/' – TLP

答えて

9

あなたに否定先読みアサーションを使用することができます。これは宿題、 `/ fooのの反対でない限り

/^(?!.*(?:foo|bar)).*$/ # doesn't contain foo or bar 

See it

+1

/sの!必要ならば必要です。一致する必要があります\ n – ysth

+0

@codaddict表現を詳細に説明できますか? – crsuarezf