Williammer
6/17/2014 - 5:33 AM

jsRegExp.match.js - pattern matches for string and tag, with local capturing feature with parentheses and global/local group match with exec

jsRegExp.match.js - pattern matches for string and tag, with local capturing feature with parentheses and global/local group match with exec in loop.

//// warm-ups
//var str = 'opacity=300';
//var reg = /opacity=([\d]{1,2})/;
//var res = (parseFloat(str.match(reg)[1]) / 100) + "";

//html tag match
var res = [];
var html = "<div class='test'><b>Hello</b> <i>world!</i></div>";
var tag = /<(\/?)(\w+)([^>]*?)>/g,
    match;
//var num = 0;
while ((match = tag.exec(html)) !== null) {
    res.push(match); //exec() will perform local match for each global matched result; while match() perform global match and return the list of matching results instead of capture.
}
//match = html.match(tag);
console.dir(res);