正则表达式包括子串而不包括另一个

时间:2018-05-10 10:43:01

标签: regex

我需要正则表达式,检查字符串是否包含foo且不包含bar 例如

foo - pass
something only with foo - pass
with foo and bar - fail
without fu but bar - fail
abracadabra - fail

1 个答案:

答案 0 :(得分:0)

试试这个:^(?!.*(bar)).*foo.*$