Javascript Regex

Created with Sketch.

Javascript Regex

Regex stands for regular expressions, which are sequences of characters that specify search patterns. In JavaScript, you’ll find regular expressions in many applications such as data validations based on patterns.

This page helps you master regex in JavaScript from scratch. After the tutorials, you’ll be confident writing regular expressions and using regex functions to match and replace strings with patterns.

Section 1. JavaScript Regex Basics

This section introduces you to 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 how to 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. Quanitifiers

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 you 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 grousp 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 is 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.

Leave a Reply

Your email address will not be published. Required fields are marked *