87,910
社区成员
发帖
与我相关
我的任务
分享
s = "aaa <input /> bbb <input style='color:red'> ccc <input style='color:blue'> ddd";
e = /(?<=^|>)\s*(\w+)|(?<=style=')(.+?)(?=')/g;
r = s.match(e);
a=[];
b=[];
s.replace(e, function(m, n) { if(n == undefined) a.push(m); else b.push(m);});
document.write(a+'<br>'); //color:red,color:blue
document.write(b); //aaa, bbb, ccc, ddd
var html=`aaa <input /> bbb <input style='color:red'> ccc <input style='color:blue'> ddd`;
html.split(/\s*(?:<input\b[^>]*?style='([^']*)'[^>]*?>|<input\s*\/?>)\s*/i).filter(function(item){
if(item) return item;
});
var html=`aaa <input /> bbb <input style='color:red'> ccc <input style='color:blue'> ddd`;
var matchs=null;
var regex=/\w+(?=\s*<|\s*$)|style=(['"])(.*?)\1/ig;
var result=[];
while((matchs=regex.exec(html))!=null){
result.push(matchs[2]?matchs[2]:matchs[0]);
}
var html=`aaa <input /> bbb <input style='color:red'> ccc <input style='color:blue'> ddd`;
var regex=/<input\b[^>]*?>/img;
html.replace(regex,function(m){
var item='';
if(m.search(/\bstyle\b/i)>-1){
item=m.match(/\bstyle=(['"])(.*?)\1/i)[2];
}
return item;
}).split(/\s+/);
var str = "aaa <input /> bbb <input style='color:red'> ccc <input style='color:blue'> ddd";
var arr = str.split(/\s*<input.*?>\s*/i);