Skip to content

Instantly share code, notes, and snippets.

@jsmithdev
Last active July 28, 2022 23:42
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 jsmithdev/0fedd6a02565c383af3fc4477bc23f26 to your computer and use it in GitHub Desktop.
Save jsmithdev/0fedd6a02565c383af3fc4477bc23f26 to your computer and use it in GitHub Desktop.
Web Components / LWC Regular Expressions
/**
* @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