简体   繁体   English

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

[英]Regex/Replace any chars inside match combination

For example 例如

var string = 'width="300" height="650"'

i would like to update height in that string and get something like 我想更新该字符串中的高度,并得到类似

string = string.replace(/height="..."/g, 'height="150"');
//... as any symbol

how to make reg expression who does not care value of height, to replace it with new one? 如何使不关心身高值的reg表达式替换为新的身高?

You can play with it here, in example: JsFiddle 您可以在这里使用它,例如: JsFiddle

var string = 'width="300" height="650"';
string = string.replace(new RegExp(/height=\"[0-9]+\"/g), 'height="150"');

DEMO 演示

for case insensitive use: 不区分大小写的用法:

.replace(new RegExp(/height=\\"[0-9]+\\"/ gi ), '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