Created
October 16, 2019 11:51
-
-
Save xmedeko/25ba8c980b146bf91da6f35af0bed611 to your computer and use it in GitHub Desktop.
HTML/XML manipulation by regular expressions in JavaScript (RegExp)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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