2

I have been trying to create a regular expression for the following problem:

 A)  PAR
 B)  1234

given strings A and B above, i want to find all matches where those values occur in order regardless of white space, etc with the following important rules:

  1. both strings A and B cannot exist as a substring to another larger string
  2. the given string B must occur after A
  3. the given string B must occur by itself and not be a part of another number

here are some example potential matches:

  1. PAR1234
  2. PAR 1234
  3. PAR 5678, 1234
  4. PAR 9991234999, 1234
  5. PAR !@#-= 1234
  6. PAR1234-122
  7. PAR#1234-233
  8. ANY TEXT PAR#1234-233

however, the following should not match:

  1. PART 1234 - PAR is substring of PART
  2. APART 1234 - PAR is substring of APART
  3. PAR 1234999 - 1234 is substring of 1234999
  4. PAR 9991234 - 1234 is substring of 9991234
  5. PAR 9991234999 - 1234 is substring of 9991234999
  6. 1234 PAR - 1234 occurs before PAR

unfortunately, i am trying to do this using REGEXP_LIKE in oracle and there is no \b

i tried

\W*PAR\W*1234

but that won't match #3 in the potential matches above. so ive attempted many variations that will work for some but not all.

i was wondering if there is an expression that could capture what i am trying to accomplish. any help would be greatly appreciated.

thanks.

bob
  • 31
  • 1
  • 2

1 Answers1

3

This solution uses \b to check for a word boundary.

\bPAR1234\b|\bPAR\b.*\b1234\b

See the demo here: https://regex101.com/r/SM8Bq1/2

Patrick Haugh
  • 59,226
  • 13
  • 88
  • 96