Extract word with regex except if it is a given word

  • 0
  • Pump00:00

I am trying to match and extract part of an URL with regex, except if it is a given word.

Here is some test data which already works:

/api/add             --> no match
/api/add/view        --> no match
/api/user1           --> matches and extracts "user1"
/api/user1/profile/  --> matches and extracts "user1"

Not working:

/api/aaa/profile/  --> matches and extracts "aaa"

Here is the current regex I have:

/^/api/(?:([^/(add)]+?))/.*?$/i

I works as I want except if it contains “a” or “d” instead of the entire “add” word.

Default Asked on February 7, 2020 in Programming.
Add Comment
  • 0 Answer(s)
  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.