O'Reilly logo

JavaScript Regular Expressions by Gabriel Manricks, Loiane Groner

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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" ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required