On the problem of regular capture

var str="hello world"; correctly matches the output "hello [] world"

Mar.20,2021

var str='hello <img src="haha.png" alt=""/>world';
let exp = /^(\S+)\s?[<].*[alt="](.*?)["]\s*[\/>]\s*(\S+)$/;
let ret = str.match(exp);
str = ret[1]+'['+ret[2]+']'+ret[3];
console.log(str);
Menu