Skip to content

Instantly share code, notes, and snippets.

@xmedeko

xmedeko/htmlregex.js

Created Oct 16, 2019
Embed
What would you like to do?
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
You can’t perform that action at this time.