Regular, the question mark is still greedy to match the problem.

var str="<iframe frameborder="0" width="640" height="498" src="https://v.qq.com/iframe/player.html?vid=a0678a3ahqx&tiny=0&auto=0" allowfullscreen=""></iframe><iframe frameborder="0" width="640" height="498" src="https://v.qq.com/iframe/player.html?vid=a0678a3ahqx&tiny=0&auto=0" allowfullscreen=""></iframe>"
var result=str.replace(/(<iframe) (.*) (width=\".*?\") (height=\".*?\") (.*)(<.*?iframe>)/g,"$1 $2 width="100%" $5 $6")
console.log(result)

I want to replace width= "640" height= "498" in iframe with width= "100%"
, so I write the above rule and find that if only one iframe in the string is successfully replaced, but if there are two iframe, it will only replace the second iframe.
ask for help, hope that in each iframe, Width= "640" height= "498" becomes width=

online debugging address http://jsbin.com/dumuxewubu/e.

= split line, problem solved =
found that the previous non-greedy matching method was added wrong, should not use (. *)? Write the question mark in parentheses.
use this

.
var result=str.replace(/(<iframe) (.*?) (width=\".*?\") (height=\".*?\") (.*?)(<.*?iframe>)/g,"$1 $2 width="100%" $5 $6")

solved, found that the previous non-greedy matching method added wrong, should not use (. *)? Write the question mark in parentheses.
use this

.
,,(.*)? ,

var result=str.replace(/(<iframe) (.*?) (width=\".*?\") (height=\".*?\") (.*?)(<.*?iframe>)/g,"$1 $2 width='100%' $5 $6")

if there are no performance requirements (but it must be much faster than using jquery to insert and modify), you can use cheerio, so you don't have to mess with regularities (and it's safe)

import cheerio from 'cheerio';
var str='<iframe frameborder="0" width="640" height="498" src="https://v.qq.com/iframe/player.html?vid=a0678a3ahqx&tiny=0&auto=0" allowfullscreen=""></iframe><iframe frameborder="0" width="640" height="498" src="https://v.qq.com/iframe/player.html?vid=a0678a3ahqx&tiny=0&auto=0" allowfullscreen=""></iframe>'
var $ = cheerio.load(str, {decodeEntities: false});
$('iframe').attr('width','100%')
console.log($.html())
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1c22cdc-3b9e1.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1c22cdc-3b9e1.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?