输入banner图图片脚本导航/分类

javascript-如何匹配"height:12px;width:56px;background:#fff;"中间的"width:56px;"?

其中":56px"是未知的,我结果希望replace之后是这样的height:12px;background:#fff;,下面是我写的,会把width后面的全部删掉的

var str = "height:12px;width:56px;background:#fff;";
str.replace(RegExp('width.*;'),'');
//=>height:12px;

回复内容:

其中":56px"是未知的,我结果希望replace之后是这样的height:12px;background:#fff;,下面是我写的,会把width后面的全部删掉的

var str = "height:12px;width:56px;background:#fff;";
str.replace(RegExp('width.*;'),'');
//=>height:12px;

str.replace(RegExp('width[^;]*;'),'');

str.replace(RegExp('width:\\w*;'), '');

var str = "height:12px;width:56px;background:#fff;";
str.replace(RegExp('width.*?;'),'');