Skip to content

Instantly share code, notes, and snippets.

  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
// please refactor me. this is *so* ugly.
var foo = /\b([A-Z0-9._%-]+)@([A-Z0-9.-]+)\.([A-Z]{2,4})\b/gi;
var text = '<p>E-Mail:&nbsp;<a href="mailto:info@foobar.net">info@foobar.net</a></p><p>Anfragen bitte an: <a href="mailto:anfrage@foobar.net">anfrage@foobar.net</a>.</p>';
var temp;
var result = [];
while( temp = foo.exec(text) ) {
result.push({
alt : temp[0],
neu : temp[1] + '&#64;' + temp[2] + '&#46;' + temp[3]
});
};
var txt_replace;
for (var i = 0; i < result.length; i++) {
txt_replace = new RegExp(result[i].alt, 'g');
text = text.replace(txt_replace, result[i].neu);
}
// text = '<p>E-Mail:&nbsp;<a href="mailto:info&#64;foobar&#46;net">info&#64;foobar&#46;net</a></p><p>Anfragen bitte an: <a href="mailto:anfrage&#64;foobar&#46;net">anfrage&#64;foobar&#46;net</a>.</p>'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment