String doesn’t contain another String, but has String with same length instead

I am trying to write regex for this String: FARM OF VEGETABLESn 1. ONIONn HU50BH/3440 n which will check:

  1. It contains FARM OF VEGETABLES
  2. It contains 1. ONION
  3. It doesn’t contain HU50BH/3440, but contain String with same length

Regex that I’m trying:

[wW]*((FARM OF VEGETABLES)[wW]*(1. ONION)[wW]*^(?!HU50BH/3440).{11}$[wW]*)[wW]*

What am I doing wrong?

Answer

From reading your question and the comments, I came up with this one. Hope it helps:

.*(FARM OF VEGETABLES).*(ONION).{7}(?!HU50BH/3440).*

EDIT: If you want to ensure it is 11 characters, you can modify it in a similar approach as this one:

.*(FARM OF VEGETABLES).*(ONION).{7}(?!HU50BH/3440)(S{11})s.*

Use S to get any character but whitespace {11} times to match the length, then afterward look for the whitespace with s.

Here is a regex101 link to show the results: https://regex101.com/r/SxNQfx/2

Leave a Reply

Your email address will not be published. Required fields are marked *