0

How to write the regrex rules for the specific given url parameter?

For exmaple, I have URL below:

  1. http://localhost:5008/api/products/productsSubscribeStatus?companyId=14
  2. http://localhost:5008/api/products/productsSubscribeStatus
  3. http://localhost:5008/api/products/productsSubscribeStatus?ccc=14

I want to a rule only match "products/productsSubscribeStatus" and only with the parameter "companyID=xx", but does not pass the url with the other parameters like the third one.

I write the regrex: \/products\/productsSubscribeStatus(\?companyId=\d+$)?, but it cannot guarantee the parameter is companyId only.

2
  • Is no query parameter also acceptable? Commented Feb 4, 2021 at 3:50
  • Yes, on my example, I want the url 1 and 2 pass, but not the third one. Only allow the url without parameter or parameter with companyId only. Commented Feb 4, 2021 at 3:55

1 Answer 1

1

I would just make the entire expected query parameter optional:

^https?://.+/products/productsSubscribeStatus(?:\?companyId=\w+)?$

Demo

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.