Book Image

JavaScript Regular Expressions

By : Gabriel Manricks, Loiane Groner, Loiane Groner [Duplicate entry]
Book Image

JavaScript Regular Expressions

By: Gabriel Manricks, Loiane Groner, Loiane Groner [Duplicate entry]

Overview of this book

Table of Contents (13 chapters)

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 script book", but not "this is a javascript book".

\B

This matches any non-word boundary.

/va\B/ matches "va" in "this is a JavaScript book", but not "this is a JavaScript book".