Developers write code, but they also write about code.
This project is to create a tutorial that explains how a specific regular expression, or regex, functions by breaking down each part of the expression and describing what it does.
GIVEN a regex tutorial
WHEN I open the tutorial
THEN I see a descriptive title and introductory paragraph explaining the purpose of the tutorial, a summary describing the regex featured in the tutorial, a table of contents linking to different sections that break down each component of the regex and explain what it does, and a section about the author with a link to the author’s GitHub profile
WHEN I click on the links in the table of contents
THEN I am taken to the corresponding sections of the tutorial
WHEN I read through each section of the tutorial
THEN I find a detailed explanation of what a specific component of the regex does
WHEN I reach the end of the tutorial
THEN I find a section about the author and a link to the author’s GitHub profile
A regex, which is short for regular expression, is a sequence of characters that defines a specific search pattern. When included in code or search algorithms, regular expressions can be used to find certain patterns of characters within a string, or to find and replace a character or sequence of characters within a string. They are also frequently used to validate input.
For example, the following regular expression can be used to verify that user input is a valid email address:
/^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/
Each component of this regex has a unique responsibility to make sure that a user enters an email address that begins with an unspecified number of characters preceding the @
symbol, followed by a domain.
Watch this introduction to regular expressions video and read Regex Tutorial: Matching a Username to learn how to identify the different components that make up a regex.
Examples:
-
Matching a Hex Value:
/^#?([a-f0-9]{6}|[a-f0-9]{3})$/
-
Matching an Email:
/^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/
-
Matching a URL:
/^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/
-
Matching an HTML Tag:
/^<([a-z]+)([^<]+)*(?:>(.*)<\/\1>|\s+\/>)$/
I will publish my findings as a GitHub gist. GitHub describes a gist as a simple way to share code snippets with others. It’s also an ideal way to demonstrate a technique, teach a principle, or show off a solution. It functions just like a repository, and you use Markdown to create it, just as you do with your READMEs. Gists can include code, images, links, and anything else you can include in a README.
© 2023 edX Boot Camps LLC. Confidential and Proprietary. All Rights Reserved.