O'Reilly logo

Object-Oriented JavaScript - Second Edition by Stoyan Stefanov, Kumar Chetan Sharma

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 D. Regular Expressions

When you use regular expressions (discussed in Chapter 4, Objects), you can match literal strings, for example:

> "some text".match(/me/);
["me"]

But, the true power of regular expressions comes from matching patterns, not literal strings. The following table describes the different syntax you can use in your patterns, and provides some examples of their use:

Pattern

Description

[abc]

Matches a class of characters.

> "some text".match(/[otx]/g);
["o", "t", "x", "t"]

[a-z]

A class of characters defined as a range. For example, [a-d] is the same as [abcd], [a-z] matches all lowercase characters, [a-zA-Z0-9_] matches all characters, numbers, and the underscore character.

> "Some Text".match(/[a-z]/g);
["o", ...

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