Created
August 8, 2021 15:41
-
-
Save ra8200/dfacb0b82a6bfdd2cbbd029458a90e02 to your computer and use it in GitHub Desktop.
RegEx Tutorial
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
In this Gist I will give a tutorial of RegEx |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Regex Tutorial
In this tutorial I am going to explain the use of regex to match emails using the expression. Regex stands for regular expression. they are used as a sequence keyboard characters, that specify a type of search pattern. In this tutorial, I will be using this regex
/^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/
. This expression can be used to validate emails using applications, websites and other technology like MongoDB.Summary
A regex (regular expression) is a sequence of characters that represents a specific search pattern. They are usually used to find a particular pattern, replace characters or even validate specific characters within a string. When used in JavaScript they are used as objects. In this tutorial I will walk you through the components of a regex and how it's used in validating an email.
Table of Contents
Regex Components
Anchors
Anchors, which are the opener and closer of the regex, are used in the email expression to match are
^
, the beginning and$
which indicates the ending of the string.Quantifiers
Quantifiers in this regex include
+
, used as an operator, that will connect the username to the email extension then to then domain ([email protected])
. Another quantifier for this regex includes{2,6}
, which will make sure the domain matches a range of 2-6 characters for the character set of[a-z\.]
.Grouping and Capturing
Group and Capturing is when a group of the #1 in this expression is
([a-z0-9_\.-]+)
that matches the user email name. The second capturing group is([\da-z\.-]+)
which will match the email service. Then lastly, capture group #3 is([a-z\.]{2,6})
to capture the domain.Bracketed Expressions
Bracketed Expressions are the character sets within the expression that hold the above captured groups. in the character set used above,
[a-z0-9_\.-]
, states that the username, of the email can include a combination of letters, numbers and the special characters ". -_". They are held in the actual [].Author
check out my github at https://github.com/ra8200 .