javascript - How to extract the alt value of image tags using regular js
给我你的怀抱
给我你的怀抱 2017-05-19 10:45:13
0
1
713

var aa="Hello<img src='aaa.gif' alt='Picture 1'>The weather is good<img src='bbb.gif' alt='Picture 2'> Ha ha"

With the above code, what I ultimately want to get using regular expressions is the following text
Hello Picture 1 The weather is good Picture 2 Haha
How should I write it?
What I can think of is to use replace, but I really don’t know how to match img and extract alt information. Please help~

给我你的怀抱
给我你的怀抱

reply all(1)
小葫芦
var reg = /(.*?)<img.+?alt=('|")(.*?).*?>([^<]*)/gi;
var str = "你好<img src='aaa.gif' alt='图1'>天气不错<img src='bbb.gif' alt='图2'>哈哈"
var resultStr = ''
var exec = ''
        
while(exec = reg.exec(str)) {
    resultStr += exec[1] + exec[3] + exec[4]
}
        
console.log(resultStr)
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template