0

Is there a regex, that matches
hahafooblababla
and does not match
hahafooblabarbla

Because I am looking for ...foo... and don't want to have ...bar... anywhere after the ...foo...

haha and bla symbolize junk/noise.

UPDATE: At first I tried with

foo.*(?!bar)

--> was not successful

user1414745
  • 1,197
  • 6
  • 21
  • 41
  • Certainly, you can use a negative lookahead. What is your regex flavor? – Wiktor Stribiżew Sep 27 '16 at 07:49
  • I ask what the flavor is because it happens people are tagging their questions with regex-negation and regex-lookarounds tags looking for a RE2 (Google Analytics, eg.) compatible regexps where one cannot use lookarounds. – Wiktor Stribiżew Sep 27 '16 at 07:56
  • I would say, that "normal" regex-es - meaning lookarounds are available - are the default in questions. If someone needs a RE2 solution, (s)he should give a hint that this is a special case. – user1414745 Sep 27 '16 at 08:09
  • BTW I don't get the -1 on my post ... not that I care so much, but was just wondering why :) – user1414745 Sep 27 '16 at 08:11
  • It is a duplicate of [RegExp exclusion, looking for a word not followed by another](http://stackoverflow.com/questions/10375045/regexp-exclusion-looking-for-a-word-not-followed-by-another). Also, you need to always include what you have tried to the question. – Wiktor Stribiżew Sep 27 '16 at 08:11

1 Answers1

0
foo(?!.*bar)
  • foo - match foo
  • (?!) - that isn't followed by
  • bar - bar
  • .* - with any amount of characters in between
ndnenkov
  • 33,260
  • 9
  • 67
  • 97