Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var str = 'let us pretend that this is a blog about gardening&cooking; here's an apostrophe & ampersand just for fun.';
- console.log('Before: ' + str);
- str = str.replace(/&(?:#x?)?[0-9a-z]+;?/gi, function(m){
- var d = document.createElement('div');
- console.log(m);
- d.innerHTML = m.replace(/&/, '&');
- console.log(d.innerHTML + '|' + d.textContent);
- return !!d.textContent.match(m.replace(/&/, '&')[0]) ? m : d.textContent;
- });
- console.log('After: ' + str);
- str.replace(/&([#x]d+;|[a-z]+;)/g, "&$1")
- str.replace(/&(?=[#x]d+;|[a-z]+;)/g, "&")
Add Comment
Please, Sign In to add comment