I need a RegEx for passing all of these URLs:
- https://www.domain.tld/service?itm_pm=de:ncp:ctr:c1cn:0:0
- https://www.domain.tld/service
- https://www.domain.tld/service/
But not these one:
I tried it with https://www.domain.tld/service[^/]* but it doesn't work
CodePudding user response:
What does "passing" mean? I'm not sure what you're asking for. I think you mean matching, but I'm not sure what criteria you're trying to show.
https://regex101.com is a great tool to test with.
CodePudding user response:
If you want to allow https://www.domain.tld/service/
specifically, do that explicitly:
https://www.domain.tld/service(/?|[^/]*)$
CodePudding user response:
Mark the end of the string
I would work with a $
delimiter for "end of string". As /
is a special character I escaped it. This may be different based on your settings. Let's use this one:
Solution with working example:
https:\/\/www\.domain\.tld\/service[^\/]*\/?$
You can play around with it here:
https://regex101.com/r/wm6Nit/1