第一组图
第二组图
代码
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>lcx</title> </head> <body> <script> function html2json(){ var h = 'svg width="100%" height="100%" viewBox="0 0 370 490"'; var patt1 = /[A-Za-z]+/; var name = patt1.exec(h); console.log(name); //console.log(name[0]); var patt2 = /([A-Za-z]+)="([^"]+)"/g; var data = {}; while(data = patt2.exec(h)){ console.log(""); console.log(data); //console.log(data[0]); //console.log(data[1]); //console.log(data[2]); } } html2json(); </script> </body> </html>
菜鸟工具网址:
http://c.runoob.com/front-end/854
这个网址还提供了很多常用正则表达式