3

I'm trying to conduct a NOT LIKE Condition1 OR Condition2 OR Condition3 equivalence in Regex. I want to find all strings which does not include any of the substrings RSBO,RRABO,RSISTA0

From this thread here I've concluded that one can write ^((?!RSISTA0).)*$ to find all strings which does not include the phrase RSISTA0

So for my requirement when I have three conditions that must be met I tried:

^((?!RSBO).)*$|^((?!RRABO).)*)$|^((?!RSISTA0).)*$

, but then I figured that the | operation should probably be a AND equivalence. For this I found that one can mimic the AND operation here

This gave me the solution:

(?=^((?!RSBO).)*$)(?=^((?!RRABO).)*)$(?=^((?!RSISTA0).)*$)

This, however, causes me to not return any strings at all, even though I know that there are some strings which does not contain any of the substrings I need to filter out.

Does anyone have any idea?

Community
  • 1
  • 1
Cenderze
  • 1,102
  • 4
  • 27
  • 50

2 Answers2

2

You are close. You just need to place the words to exclude in the negative lookahead like this:

^(?:(?!RSBO|RRABO|RSISTA0).)*$

It won't match any word containing RSBO, RRABO or RSISTA0 but will match any other text.

See the demo

Niitaku
  • 835
  • 9
  • 19
  • Thanks! I've just tested this solution in the program I use, and it works perfectly! I never imagined I would get a working solution this quick. :) – Cenderze Feb 23 '17 at 14:47
1
^((?!RSBO)(?!RSISTA0)(?!RRABO).)*$

I believe this does the trick. Tested with success at regex101. Probably inefficient since it looks ahead at every character but I can't find a way around doing it like this.

Edit: I don't think the positive look ahead at the beginning was needed so I removed it from my original answer.

SFDC Noob
  • 211
  • 1
  • 6