正则表达式匹配行的一部分并否定查找行的其余部分(不匹配单词)

Regex to match parts of line and negative-lookup the rest of the line (not match a word)

是否有匹配
的正则表达式 哈哈fooblababla
并且不匹配
hahafooblabarbla

因为我正在寻找 ...foo... 并且不想在 ...foo... 之后的任何地方都有 ...bar...

哈哈bla代表junk/noise.

更新: 起初我试过

foo.*(?!bar)

--> 没有成功

foo(?!.*bar)
  • foo - 匹配 foo
  • (?!) - 后面没有
  • bar - bar
  • .* - 中间有任意数量的字符