Regex loop

by JibstaMan

HTML

<ul>
</ul>

CSS

ul {
     font-family: Consolas, monaco, monospace;
}

JavaScript

var emails = "[email protected] [email protected],[email protected], [email protected]\[email protected]\n     [email protected]   \t \n [email protected]     [email protected],\n\[email protected]",
    regex = /(?:([a-zA-Z0-9.!#$%&’*+\/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)+)(?:\s|\n|,|\.|$)+)/g;

var match, matches = [];
while (match = regex.exec(emails)) {
    matches.push(match[1]);
}

console.log(matches);
for (var i = 0; i < matches.length; i++)
	$('ul').append('<li>"' + matches[i] + '"</li>');