asd*_*asd 2 javascript regex replace match
我需要应用regexp来替换字符串块.
这是我的代码:
var style = "translate(-50%, -50%) translate3d(3590px, 490px, 0px) rotateX(0deg) rotateY(0deg) rotateZ(0deg) scale(1)";
style = style.replace(/translate3d\(.+\)/,"asdf");
Run Code Online (Sandbox Code Playgroud)
我需要替换那个部分:"translate3d(3590px, 490px, 0px)"
但它不起作用,因为它取代直到最后一个")"所以它将是:"translate(-50%, -50%) asdf"
使用非贪婪的正则表达式:
style = style.replace(/translate3d\(.+?\)/,"asdf");
Run Code Online (Sandbox Code Playgroud)
放在?后面+使用最短的匹配而不是最长的匹配.