Skip to content

Instantly share code, notes, and snippets.

@patrbraun
Last active July 8, 2021 04:21
Show Gist options
  • Select an option

  • Save patrbraun/d64015bd06359bd9a928125432fb97d5 to your computer and use it in GitHub Desktop.

Select an option

Save patrbraun/d64015bd06359bd9a928125432fb97d5 to your computer and use it in GitHub Desktop.
Describing matching an Email regex expression: `/^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/`

Regex-Tutorial

Introductory paragraph (replace this with your text)

Summary

Matching an Email: /^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/

Table of Contents

Regex Components

Anchors

^ Matches any string that start with characters placed after it.

^Hello     Matches a string that starts with Hello.

$ Matches any string that ends with characters placed before it.

World$     Matches a string that ends with World.

Quantifiers

+ Matches a string that has one or more of the group before it.

a+    String has one or more a in a row.

{2,6} Matches a string followed by 2 up to 6 of the group before it.

a{2,6}    String has 2 up to 6 a characters in a row.

Grouping Constructs

a(bc) Creates a group of the characters bc

Allows you to group bracket expressions, character classes, quantifiers, and other regex components together.

Bracket Expressions

[abc] Matches a string with either a, b, or c. Same as [a-c]

[a-z0-9]    String has a single character that is a through z or 0 through 9.

Character Classes

\d Matches a character that is also a digit.

Character Escapes

\? In order to search the following character they must be preceded by a backslash ^.[$()|*+?

\\. Matches a string that contains a period.

Explanation

/^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/

-There are three major sections

- /^([a-z0-9_\.-]+)
  - ^() means the string starts with the group in the parenthesis.
  - ([a-z0-9_\.-]+) => []+ the string contains any number of the characters in the bracket expression.
  - a-z0-9_\.- contains characters a through z, 0 through 9, underscore, period, or a dash.
    - The string begings with any number of characters a through z, 0 through 9, underscore, period, or a dash.

- @([\da-z\.-]+)
  - The first section is followed by an @ character followed by the next group ([\da-z\.-]+)
  - [\da-z\.-]+ => the string contains any number of the characters in the bracket expression.
  - \da-z\.- Contains a character that is a digit (\\d), a through z, period, or a dash.
    - The string contains an @ sign followed by any number of digits, a through z, period, or dash.

- \.([a-z\.]{2,6})$/`
  - The second section is follow by a period and a string ending with the final group ()$
  - ([a-z\.]{2,6}) Contains 2 up to 6 character of the preceding bracket expression.
  - [a-z\.] Contains a through z, or period.
    - The string contains a period followed by a string ending with more than 2 and up to 6, a through z or periods.
    
- Final
  - The string begings with any number of characters a through z, 0 through 9, underscore, period, or a dash 
  
  - followed by an @ sign followed by any number of digits, a through z, period, or dash followed by a period 
  
  - then ending with more than 2 and up to 6, a through z or periods.

Author

https://github.com/patrbraun

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