Search code examples
regexregex-lookarounds

"REGEX" Match string not containing specific substring


I will give an example, I have two strings:

FL_0DS906555B_3661_27012221225012_V001_S

FL_0DS906555C_3661_27012221225012_V001_S

And I want to get any string, that has no "0DS906555B" in it, has "2701222122" in it and "5012" is in range of 5003-5012.

My regex looks like this:

^.*(?!.*0DS906555B).{6}2701222122(500[3-9]|501[0-2]).*$

unfortunately it keeps matching everything all the time. I have looked into many posts here but nothing helped for me since people usually asked for less complex, smaller strings.

Thank you


Solution

  • Try (regex101):

    ^(?!.*0DS906555B)(?=.*_2701222122(?:500[3-9]|501[012])_).*$