繁体   English   中英

正则表达式/替换匹配组合中的任何字符

[英]Regex/Replace any chars inside match combination

例如

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”');

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM