Skip to content

Instantly share code, notes, and snippets.

@Spikeophant
Created November 4, 2022 01:03
Show Gist options
  • Save Spikeophant/8cb5da3cb52e4761f3770332322541e6 to your computer and use it in GitHub Desktop.
Save Spikeophant/8cb5da3cb52e4761f3770332322541e6 to your computer and use it in GitHub Desktop.
Tutorial for Regex Statement
# 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