1

I want to filter strings that do not contain one of the following strings

ABCD
IJKL

I have tried to create the regex using regex101

https://regex101.com/r/gI6sN8/1

What is wrong here?

tried also the answer from Regex for string not containing multiple specific words

but it did not work https://regex101.com/r/gI6sN8/3

Community
  • 1
  • 1
Bick
  • 17,833
  • 52
  • 146
  • 251
  • enable `gm` flag..see https://regex101.com/r/gI6sN8/2 – rock321987 Aug 16 '16 at 11:44
  • Anchored regular expressions need `m` flag. Also for matching *all cases* you would need `g` flag. – frogatto Aug 16 '16 at 11:52
  • It works. https://regex101.com/r/gI6sN8/4. Now, what is your real environment? Does it allow lookarounds? And please do not delete your identical questions, just update them. If you can use lookarounds, this question is still a dupe of [*Regex for string not containing multiple specific words*](http://stackoverflow.com/questions/7801581/regex-for-string-not-containing-multiple-specific-words). – Wiktor Stribiżew Aug 16 '16 at 11:53
  • So, shall we close this one as well? – Wiktor Stribiżew Aug 16 '16 at 12:01

1 Answers1

1

I think you're looking for something like this?

https://regex101.com/r/gI6sN8/10

(?=ABCD|IJKL)(.*)
(?= // This is a look ahead
ABCD|IJKL // ABCD or IJKL
) // Close the look ahead

(.*) // Get EVERYTHING if the line contains the look ahead and return me that line

But your question is a little unclear. If you can tidy it up and give a sharper description I'm sure we will be able to help you more.

TolMera
  • 452
  • 10
  • 25
  • This phrase finds when one of the substrings string is contained in each string. I was looking for when non of the substring is contained. – Bick Aug 16 '16 at 15:09
  • If you able to use GREP, use a -v to invert your match. Otherwise a Negative Look Behind might be your best approach. – TolMera Aug 16 '16 at 15:37