/disconnect/<backend>/foo/<association_id>/
を正規表現マッチを交換し、私は
/disconnect/:backend/foo/:association_id/
がパスに<pattern>
の任意の数があるかもしれません取得したいのですが。
/disconnect/<backend>/foo/<association_id>/
を正規表現マッチを交換し、私は
/disconnect/:backend/foo/:association_id/
がパスに<pattern>
の任意の数があるかもしれません取得したいのですが。
は<と>の間の文字列のすべてのインスタンスにマッチするreplace
方法
var str = '/disconnect/<backend>/foo/<association_id>/',
reg = /<([^>]+)>/g;
console.log(str.replace(reg, ":$1"));
何この方法は?ライブデモhttp://jsfiddle.net/d4N9s/
var mystring = "/disconnect/<backend>/foo/<association_id>/"
var middle = mystring.replace(/>/g , "")
console.log(middle.replace(/</g , ":"));
クリーナー方法:あなたがURLの構造は一貫してしようとしているわかっている場合
var mapO = {
'>':"",
'<':":",
};
str = mystring.replace(/<|>/gi, function(matched){
return mapO[matched];
});
console.log(str);
は、あなたがスラッシュで文字列を分割し、その後に部分文字列を取得することができますあなたが望むインデックス。 – Matthew