Last active
August 7, 2020 18:06
-
-
Save bluepnume/081f542ef86be190b45e867dea324846 to your computer and use it in GitHub Desktop.
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
/* @jsx regex.node */ | |
import { regex, Regex, RegexGroup as Group, RegexText as Text, RegexWord as Word } from 'jsx-pragmatic'; | |
const Dot = () => { | |
return <Text>.</Text>; | |
}; | |
const At = () => { | |
return <Text>@</Text>; | |
}; | |
const emailRegex = ({ providers, tlds, optionalLastName = true }) => { | |
return ( | |
<Regex> | |
<Word /> | |
<Group optional={ optionalLastName }> | |
<Dot /> | |
<Word /> | |
</Group> | |
<At /> | |
<Group union name='provider'> | |
{ providers.map(provider => <Text>{ provider }</Text>) } | |
</Group> | |
<Dot /> | |
<Group union name='tld'> | |
{ tlds.map(tld => <Text>{ tld }</Text>) } | |
</Group> | |
</Regex> | |
); | |
}; | |
const email = '[email protected]'; | |
const match = email.match(emailRegex({ | |
optionalLastName: false, | |
providers: [ 'paypal', 'google', '$mail' ], | |
tlds: [ 'com', 'org', 'net' ] | |
})); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment