Reputation: 41745
For a given URL,
/disconnect/<backend>/foo/<association_id>/
I'd like to get
/disconnect/:backend/foo/:association_id/
There could be any number of <pattern>
s in a path.
Upvotes: 1
Views: 59
Reputation: 38552
What about this way? Live Demo http://jsfiddle.net/d4N9s/
var mystring = "/disconnect/<backend>/foo/<association_id>/"
var middle = mystring.replace(/>/g , "")
console.log(middle.replace(/</g , ":"));
Cleaner way:
var mapO = {
'>':"",
'<':":",
};
str = mystring.replace(/<|>/gi, function(matched){
return mapO[matched];
});
console.log(str);
Upvotes: 1
Reputation: 169
/<(.*?)>/g
That will match all instances of a string between < and >. You can use some simple JavaScript to replace each instance pretty easily.
Upvotes: 0