我正在尝试使用.replace('width=".*"', 'width="100"')
,因为原始的string
中width
可以是任何值。但目前这并没有改变任何东西。
https://jsfiddle.net/bobbyrne01/8p404z5t/
html
<div id="1"></div><br/>
<div id="2"></div>
javascript
var fullURL = '<iframe class="embedly-embed" src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fi.imgur.com%2F…key=2aa3c4d5f3de4f5b9120b660ad850dc9&type=video%2Fmp4&schema=imgur" width="406" height="720" scrolling="no" frameborder="0" allowfullscreen></iframe>';
document.getElementById('1').textContent = fullURL;
var moddedURL = fullURL.replace('width=".*"', 'width="100"');
document.getElementById('2').textContent = moddedURL;
结果 ..
<iframe class="embedly-embed" src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fi.imgur.com%2F…key=2aa3c4d5f3de4f5b9120b660ad850dc9&type=video%2Fmp4&schema=imgur" width="406" height="720" scrolling="no" frameborder="0" allowfullscreen></iframe>
<iframe class="embedly-embed" src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fi.imgur.com%2F…key=2aa3c4d5f3de4f5b9120b660ad850dc9&type=video%2Fmp4&schema=imgur" width="406" height="720" scrolling="no" frameborder="0" allowfullscreen></iframe>
\d
匹配一个数字,表达式\d*
匹配零个或多个连续出现的\d
。例如,“9”
将匹配"\d"
,但不匹配"999"
。 - thefourtheye