Reputation: 2205
i am trying to remove a parameter from url with regexp and i keep getting Uncaught SyntaxError: Unexpected token
var url=window.location.href;
//Remove p first
url = url.replace(/p/([0-9]+)/, '');
i am trying to remove the p parapemeter /p/*
my testing url is http://mycompany.com/en/category/p/5
What am i doing wrong
Thanks
Upvotes: 0
Views: 599
Reputation: 30971
Apart of prepending the /
with a backslash (as it was stated in a comment to
your post), another hint: As you want only to delete the matched string,
the capturing group here is not needed.
So change your code to:
url = url.replace(/p\/[0-9]+/, '');
Or even shorter option:
url = url.replace(/p\/\d+/, '');
Upvotes: 1