Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
例如
var string = 'width="300" height="650"'
我想更新该字符串中的高度并得到类似的东西
string = string.replace(/height="..."/g, 'height="150"'); //... as any symbol
如何制作不关心高度值的reg表达式,用新的替换它?
你可以在这里玩它,例如: JsFiddle
var string = 'width="300" height="650"'; string = string.replace(new RegExp(/height=\"[0-9]+\"/g), 'height="150"');
演示
对于不区分大小写的使用:
.replace(new RegExp(/height=\"[0-9]+\"/ gi ), 'height="150"');