Created
November 4, 2022 01:03
-
-
Save Spikeophant/8cb5da3cb52e4761f3770332322541e6 to your computer and use it in GitHub Desktop.
Tutorial for Regex Statement
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
# Tutorial for Regex statement | |
Introductory paragraph (replace this with your text) | |
## Summary | |
I will explain each piece of this regex which can identify an email address /^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/ | |
We'll start with the first characters here, ^ matches the position at the start of the string. | |
([a-z0-9_\.-]+) is the first capture group. | |
This group matches the group between one and unlimited times giving back as necessary, considered greedy. The group matches as follows: | |
* a-z matches a single char between a and z case sensitive. | |
* 0-9 matches a single char between 0 and 9 case sensitive. | |
* _ matches _ literally. | |
* \. matches . literally. | |
* - matches - literally. | |
@ is next, it is matched literally. | |
The second capture group ([\da-z\.-]+) again has the plus, which makes it return as many times as possible, again greedy. | |
[\da-z\.-] matches a single char in the list below: | |
* \d matches a digit, equiv to [0-9] | |
* a-z matches a single char between a and z case sensitive. | |
* \. matches . literally. | |
* - matches - literally. | |
\. matches . literally | |
The third, and final, capture group ([a-z\.]{2,6}) matches a single character in the list below between 2 and 6 times {2,6}: | |
* a-z matches a single char between a and z case sensitive. | |
* \. matches the character . literally. | |
$ asserts the position at the end of the string |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment