Reputation: 3183
I'm trying to match and replace the following: /?&
with /?
collage_url.match(/\/?&/) == '/?';
However this doesn't seem to work. Anyone able to help me out here, thanks
Upvotes: 0
Views: 40
Reputation: 9664
You do not need regex for this. Do this collage_url = collage_url.replace('/?&', '/?')
If you want to use regex, then do this collage_url = collage_url.replace(/\/\?&/, '/?')
as ?
represents optional quantifier.
Upvotes: 2
Reputation: 369134
Use String.replace
'url/?&'.replace(/\/\?&/, '/?')
// => "url/?"
?
has special meaning in regular expression: 0 or 1 match of preceding pattern; You need to escape ?
to match it literally.
Upvotes: 1