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

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -