Reputation: 141
This is my string:
hello/page/2/bye
This is what I would have (please note that "2" could be any number, "page" is always "page":
hello/bye
How can I do with str.replace() using jQuery?
Upvotes: 0
Views: 433
Reputation: 5705
This will do it (without jQuery):
var str = 'hello/page/2/bye';
str = str.replace(/page\/\d+\//,'');
The slashes need to be escaped (so they become \/
), \d+
is any number, one or more times (so it also matches e.g. page/12/
Demo: http://jsfiddle.net/dd5aohbc/
Upvotes: 2