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

Boundaries

In the following table, you can find the patterns for boundaries, which will tell the Regex what position to do the matching in.

Pattern

Description

Example

^

This matches the beginning of an input. If the multiline flag is set to true, it also matches immediately after the (\n) line break character.

/^ The/ matches "The" in "The stars", but not "In The stars".

$

This matches the end of an input. If the multiline flag is set to true, it also matches immediately before the (\n) line break character.

/and$/ matches "and" in "land", but not "and the bar".

\b

This matches any word boundary (test characters must exist at the beginning or at the end of a word within the string).

/va\b/ matches "va" in "this is a java ...

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