What does the forward slash mean within a JavaScript regular expression?

The slashes indicate the start and end of the regular expression.

The g at the end is a flag and indicates it is a global search.

From the docs:

Regular expressions have four optional flags that allow for global and
case insensitive searching. To indicate a global search, use the g
flag. To indicate a case-insensitive search, use the i flag. To
indicate a multi-line search, use the m flag. To perform a “sticky”
search, that matches starting at the current position in the target
string, use the y flag. These flags can be used separately or together
in any order, and are included as part of the regular expression.

To include a flag with the regular expression, use this syntax:

 var re = /pattern/flags;

Leave a Comment