Appendix A. JavaScript Regex Cheat Sheet

In this appendix, you can find a summary of the patterns used in regular expressions in JavaScript along with their descriptions, and a list of useful methods to test and create regular expressions.

The following Regex topics will be covered in this appendix:

  • Character classes and literals
  • Character sets
  • Boundaries and quantifiers
  • Grouping, alternation, and back reference
  • Useful methods

Character classes

In the following table, you can find the patterns for character classes, which tell the Regex to match a single character:

Pattern

Description

Example

.

This matches any character, except newline or another unicode line terminator, such as (\n, \r, \u2028 or \u2029).

/f.o/ matches "fao", "feo", and "foo" ...

Get JavaScript Regular Expressions now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.