Skip to content

Instantly share code, notes, and snippets.

@xmedeko
Created October 16, 2019 11:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xmedeko/25ba8c980b146bf91da6f35af0bed611 to your computer and use it in GitHub Desktop.
Save xmedeko/25ba8c980b146bf91da6f35af0bed611 to your computer and use it in GitHub Desktop.
HTML/XML manipulation by regular expressions in JavaScript (RegExp)
/**
* JS remove HTML/XML attribure regexp.
*/
function removeAttribute(html, tagName, attrName) {
return html.replace(new RegExp(`(<${tagName}.*?)\\s+${attrName}=(["']).*?\\2(.*?>)`, 'gmi'), '$1$3');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment