0

I am trying to write a regex that accepts url with pathname of the form

/exmaple/XXXXX

Here,XXXXX can be a string of alphanumeric keywords but it should not be "create" or "add".

I have created the regex for accepting alphanumeric but I am unable to find a way to add exceptions of "create" or "add".

Prashant Agrawal
  • 660
  • 9
  • 24

1 Answers1

4

The negative lookahead is your friend, foo(?!pattern) means foo will not match if pattern matches immediately after foo. Like other lookarounds, negative lookaheads are not capture groups.

/\/example\/(?!create|add)[A-Za-z0-9]+/
Paul S.
  • 64,864
  • 9
  • 122
  • 138