Javascript Regex

Regex stands for regular expressions. Regex is a powerful tool that allows you to define search patterns.

In JavaScript, regular expressions are incredibly useful for various tasks such as data validations, search and replace text, and data parsing.

This tutorial series helps you master regex in JavaScript from scratch. By the end of the series, you’ll gain the skills and confidence to write regular expressions and to match, search, and manipulate strings effectively.

Section 1. JavaScript Regex Basics

This section introduces the basic Javascript Regex including related regular expression methods, character classes, anchors, and word boundaries.

  • Regular expressions – learn how to create regular expressions in JavaScript and use them to search and replace strings using patterns and flags.
  • Character classes – show you how to form a regular expression with character classes that allow you to match any character in the character sets.
  • Anchors – learn how to use anchors in regular expressions to match at the beginning or end of a string.
  • Word Boundaries – show you how to use the word boundaries in the regular expressions to carry the match whole word only.

Section 2. Quantifiers

This section shows you how to use quantifiers to match a rule a number of times.

  • Quantifiers – learn how to use quantifiers to match a number of instances of a character, group, or character class in a string
  • Greedy quantifiers – show you how to use the greedy quantifiers to match as much as possible and return the largest matches.
  • Non-greedy quantifiers – show you how to use non-greedy quantifiers to match their preceding elements as little as possible and return the smallest matches.

Section 3. Sets and Ranges

This section shows how to match a string with a set or range.

  • Sets and Ranges – guide you on how to use the sets and ranges to match a set of characters.

Section 4. Groupings

This section discusses the grouping techniques to extract a portion of the match, reference the group, and use alternation.

  • Capturing Groups – show you how to use capturing groups to get the matched values.
  • Backreferences – reference capturing groups inside regular expressions.
  • Alternation – learn how to use the alternation which is like the OR operator in regular expressions.

Section 5. Look Around

This section introduces you to various types of look-around mechanisms.

  • Lookahead – match X only if it is followed by Y.
  • Lookbehind – match X only if it is preceded by Y.

Section 6. Regex methods

This section discusses the JavaScript regex-related methods in depth.

  • match() – match a string against a regular expression.
  • replace() – find matches against a regular expression and replace the matches with a new substring.
Was this tutorial helpful ?