Skip to content

Instantly share code, notes, and snippets.

@tanyaleepr
Last active April 11, 2022 00:47
Show Gist options
  • Save tanyaleepr/d3ec5777e6162b92db398bf8986329f1 to your computer and use it in GitHub Desktop.
Save tanyaleepr/d3ec5777e6162b92db398bf8986329f1 to your computer and use it in GitHub Desktop.
Regex tutorial for Matching an Email

Regex tutorial for Matching an Email

Regular expressions is used to detect particular character patterns within a string. Inside one string, you may also locate and modify a symbol or a group of letters. They're also often used to double-check data. An example is to valid an e-mail addresses, the regex matches character information.

Summary

This is the regex code for this tutorial is: /^([a-z0-9_.-]+)@([\da-z.-]+).([a-z.]{2,6})$/

Table of Contents

Regex Components

Anchors

The following anchors are used to contain this regular expression: ^ to start, and $ to finish.

Quantifiers

We used + in this example to indicate that there is another sequence that needs to be matched as a greedy quantifier. Another greedy quantifier we used was 2,8 to signal that the input should be a minimum of 2 characters and a maximum of 8 characters.

Character Classes

The character class /d is utilized in this regular expression, which in JavaScript classifies the usage of any digit from 0 to 9.

Grouping and Capturing

In this example, three groups are being captured. The username of the e-mail account [a-z0-9_.-] belongs to Group #1. The domain name or e-mail service utilized [da-z.-] is captured in the second group. Lastly, the third group captures the domain extention (.com or .net) [a-z.]{2,8}

Extra information:

[Regular Expression Tutorial] (https://coding-boot-camp.github.io/full-stack/computer-science/regex-tutorial) [Regex tutorial — A quick cheatsheet by examples] (https://medium.com/factory-mind/regex-tutorial-a-simple-cheatsheet-by-examples-649dc1c3f285) [regexLearn] (https://regexlearn.com/)

Author

Hi, I'm Tanya Gonzalez. For any questions or suggestions, you can contact me at [My GitHub] (https://github.com/tanyaleepr)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment