Removing url params using regex -
i have problem removing params url starting on ":". have example path like:
/foo/:some_id/bar/:id
i archive following result:
/foo/bar
i tried create regex. figured out this:
\/:.*?\/
but 1 removes :some_id still leaves :id part. can tell me how can modify regex remove params?
your regex requires /
present @ end. cannot remove /
regex since .*?
won't match then. use negated character class:
\/:[^\/]+
see regex demo
pattern details:
\/:
- matches literal/:
[^\/]+
- matches 1+ characters other/
[^...]
defines negated character class matching characters defined in class.
Comments
Post a Comment