Last active
July 28, 2022 23:42
-
-
Save jsmithdev/0fedd6a02565c383af3fc4477bc23f26 to your computer and use it in GitHub Desktop.
Web Components / LWC Regular Expressions
This file contains hidden or 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
/** | |
* @description Matches name of component - "ui-comp" from `<ui-comp class="ok">EVERYTHING</ui-comp>` | |
* @return {Array} array of matches | |
* @demo regexr.com/6qp3v | |
**/ | |
export function nameUse(s) { | |
return s.match(new RegExp(/(?<=<)((\w*)(-\w*))(-\w*)*/, 'g')); | |
} | |
/** | |
* @description Matches whole use of component `<ui-comp class="ok">EVERYTHING</ui-comp>` | |
* @return {Array} array of matches | |
* @demo regexr.com/6qp45 | |
**/ | |
export function wholeUse(s) { | |
return s.match(new RegExp(/((<\w*)(-\w*).*)((.|\n)*)((<\/\w*)(-\w*).*)/, 'g')); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment