2

I have a regular expression (built in adobe javascript) which finds string which can be of varying length.

The part I need help with is when the string is found I need to exclude the extra characters at the end, which will always end with 1 1.

This is the expression:

var re = new RegExp(/WASH\sHANDLING\sPLANT\s[-A-z0-9 ]{2,90}/);

This is the result:

WASH HANDLING PLANT SIZING STATION SERVICES SHEET 1 1 75 MOR03 MUP POS SU W ST1205 DWG 0001

I need to modify the regex to exclude the string in bold beginning with the 1 1.

Keep in mind the string searched for can be of varying length hence the {2,90}

Can anyone please advise assistance in modifying the REGEX to exclude all string from 1 1

Thank you

JoJo
  • 115
  • 2
  • 10

1 Answers1

1

You may use a positive lookahead and keep the same functionality:

/WASH\sHANDLING\sPLANT\s[-A-Za-z0-9 ]{2,90}(?=\b1 1\b)/
                                           ^^^^^^^^^^^

The (?=\b1 1\b) lookahead requires 1 1 as whole "word" after your match.

See the regex demo

Also, note that [A-z] matches more than just letters.

Community
  • 1
  • 1
Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
  • 1
    Thank you very much for your help much appreciated, the regex with the positive lookahead works and the string in bold is excluded. – JoJo Apr 12 '17 at 23:42