Javascript JS-(不带jQuery):regexp元数据

Javascript JS-(不带jQuery):regexp元数据,javascript,regex,Javascript,Regex,我正在尝试查找并替换类名中的字符串。 我使用的函数返回类的“元数据”: e、 g: 因此,函数metadata.action将返回我“/myurl/param1/param2” 现在我需要以一种通用的方式用regexp更改这个值 这是我的RegExp,当然它不起作用:( “opts.attribute”在本例中是“action”。现在我需要找到“opts.attribute”之后第一次出现的引号,并将其替换为“opts.value” 我不知道怎么做,RegExp是我个人的噩梦:-/Regex与非

我正在尝试查找并替换类名中的字符串。 我使用的函数返回类的“元数据”:

e、 g:

因此,函数metadata.action将返回我“/myurl/param1/param2”

现在我需要以一种通用的方式用regexp更改这个值

这是我的RegExp,当然它不起作用:(

“opts.attribute”在本例中是“action”。现在我需要找到“opts.attribute”之后第一次出现的引号,并将其替换为“opts.value”


我不知道怎么做,RegExp是我个人的噩梦:-/

Regex与非常规数据确实是一场噩梦。
var oldclass="atestclass {action : '/myurl/param1/param2'}";
var regExp = new RegExp("(\\{\\s*"+opts.attribute+"\\s*:\\s*').*?'", 'igm');
var newclass = oldclass.replace(regExp, "$1"+opts.value.replace('$', '$$')+"'");
var regExp = new RegExp(opts.attribute + '\'.\'','igm');
var oldclass="atestclass {action : '/myurl/param1/param2'}";
var regExp = new RegExp("(\\{\\s*"+opts.attribute+"\\s*:\\s*').*?'", 'igm');
var newclass = oldclass.replace(regExp, "$1"+opts.value.replace('$', '$$')+"'");