1

On the following string I want to remove sort=*. I can get this done by run loop over it But want to get it done using regex which is new to me.

So start point should be "sort" and end point should be '&' and sort value could be *

I have created this one but dont how to add end point

string.replace((sort=*)\w,'')



"category_id=249&sort=name&category_filter=15&"

to

"category_id=249&category_filter=15&"
2
  • 1
    Modern browsers provide URLSearchParams to work with query strings. Commented Jun 16, 2017 at 7:51
  • 1
    You can build string by chosen properties from something object, it could be more declarative approach than editing existing string. Commented Jun 16, 2017 at 8:01

1 Answer 1

1

You ca use this regex instead (sort=.*?&), which can match every thing from sort= until the first occurrence of &

regex demo

Output

category_id=249&category_filter=15&
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.