Skip to content

Instantly share code, notes, and snippets.

@hao-ji-xing
Created June 28, 2014 06:06
Show Gist options
  • Save hao-ji-xing/eb84ff5df3d01b8ac3af to your computer and use it in GitHub Desktop.
Save hao-ji-xing/eb84ff5df3d01b8ac3af to your computer and use it in GitHub Desktop.
parse-html
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<textarea name="" id="txt" cols="30" rows="10">
<tr><td id="</td>">aaa</td>
<td>aaa</td>
<td>bbb</td>
<td>ccc</td>
<td>eee</td>
</tr>
</textarea>
<script>
function htmlParser(str, callback){
var reg = /(?:<(?:"(?:\\.|[^"])*"|'(?:\\.|[^'])*'|[^<>"'])*>|[^<>]+)/g;
var curr = null;
while(curr = reg.exec(str)){
callback(curr[0]);
}
}
htmlParser(document.getElementById('txt').value, function(text){
console.log(text);
})
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment