クエリ文字列で一致するものを見つけるためのパターンがあります。
'url.com/foo/bar?this=that&thing=another'.replace(/(thing=)([^&]*)/, '$1test')
私ができるようにしたいのは、次のように一致するパラメータとして変数値を使用することです。
'url.com/foo/bar?this=that&thing=another'.replace('/(' + key + '=)([^&]*)/', '$1test')
[編集]コードがどのように使用されているかについてのコンテキストは次のとおりです。
GetSrcParam: function(key, value) {
var newSrc = $(this._image).attr('src'),
pattern = '(' + key + '=)([^&]*)';
if (newSrc.match(pattern) == null)
newSrc += '&' + key + '=' + value;
else
newSrc = newSrc.replace(newSrc, '$1' + value);
return newSrc;
}
しかし、それは意図したとおりに機能していません-誰かが助けることができますか?