Skip to content

Instantly share code, notes, and snippets.

@t2na
Last active August 29, 2023 21:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save t2na/09c9df9c76c417c767441fd1afe0f12a to your computer and use it in GitHub Desktop.
Save t2na/09c9df9c76c417c767441fd1afe0f12a to your computer and use it in GitHub Desktop.
Email Address Verification Regex
# Email Address Verification Regex
Regular expressions, commonly abbreviated as "regex" or "regexp", are powerful patterns used for string matching and manipulation. Originating from formal language theory in computer science, they have become an indispensable tool in text processing, data validation, and search operations across programming and scripting languages. By defining specific patterns of characters, regex allows users to identify, extract, replace, or split strings in ways that simple string methods cannot achieve, making them a cornerstone of sophisticated text manipulation in software development.
## Summary
The regex I will be explaining is used for verifying that a piece of user input is a valid email address: `/^(\w+|[0-9]+)@\w+\.\w/i`
## Table of Contents
- [Anchors](#anchors)
- [Quantifiers](#quantifiers)
- [Grouping Constructs](#grouping-constructs)
- [Bracket Expressions](#bracket-expressions)
- [Character Classes](#character-classes)
- [The OR Operator](#the-or-operator)
- [Flags](#flags)
- [Character Escapes](#character-escapes)
## Regex Components
the different pieces of the regex (see below)
### Anchors
`^`: This is the start of line/string anchor. It asserts that the subsequent pattern must match at the very beginning of the string or line. In other words, the string must start with a letter or number.
### Quantifiers
`+`: this quantifier means that the preceding element must be used one or more times.
### Grouping Constructs
`(\w+|0-9+)`: This grouping construct is denoted by the paranthesis, and allows the users input to include either one or more word characters or one or more numbers.
### Bracket Expressions
`[0-9]`: marches any single digit from 0 to 9.
### Character Classes
`\w`: allows for a word character, such as a-z.
`0-9`: allows for any number from 0 to 9.
### The OR Operator
`(\w+|0-9+)`: the regex will attempt to match either one or more word characters OR one or more digits.
### Flags
`i`: this is the case insensitive flag, which allows the regex to match characters regardless of case. For example, "A" or "a" would both be considered matches for the pattern `\w`.
### Character Escapes
`\.`: forces the user to input a dot, as opposed to using `.` as a metacharacter
`\w`: allows the user to enter any word character, as oppossed to forcing a "w"
## Author
Zach Antunes is a student in the UC Berkeley full stack coding bootcamp. GitHub: https://github.com/t2na
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment