Created
May 2, 2022 23:18
-
-
Save danielnass/c86714ef969a05405bc43fd423c35f02 to your computer and use it in GitHub Desktop.
Regex for searching a React component by their name. Search just for the specific name, excluding extensions.
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
/* Search only for the specific name, excluding name extensions | |
** This example below will found | |
** | |
** <Anchor>Anchor Text</Anchor> | |
** | |
** <Anchor booleanProp>Anchor Text</Anchor> | |
** | |
** <Anchor prop="text">Anchor Text</Anchor> | |
** | |
** <Anchor prop={localProp}>Anchor Text</Anchor> | |
** | |
** <Anchor | |
** prop1 | |
** prop3="text" | |
** prop4={test} | |
** > | |
** Anchor Text | |
** </Anchor> | |
** | |
** <Anchor theme="icon" icon="xs-sun" /> | |
** | |
********************************************** | |
** | |
** And will not found these below | |
** | |
** <AnchorHey>Anchor Text</Anchor> | |
** | |
** <AnchorButton booleanProp>Anchor Text</Anchor> | |
** | |
** <AnchorMaybe prop="text">Anchor Text</Anchor> | |
** | |
** <AnchorStyles prop={localProp}>Anchor Text</Anchor> | |
** | |
** <AnchorModal | |
** prop1 | |
** prop3="text" | |
** prop4={test} | |
** > | |
** Anchor Text | |
** </Anchor> | |
** | |
** <AnchorSelfClosing theme="icon" icon="xs-sun" /> | |
** | |
** And any other extension | |
*/ | |
const regex = /<\bAnchor\b(.|\n|>)*?(\/>|<\/\bAnchor\b>)/gi; | |
const regexSelfClosingComponents = /<\bIcon\b(.|\n|>)*?\/>/gi; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment