JavaScript RegExp ^ Quantifier

Definition and usage

^n Quantifier matches any string that starts with n String that starts with

Tip:Please use n$ Quantifier matches any string that starts with n String at the end.

Example

Example 1

Perform a global search for "Is" at the beginning of the string:

let text = "Is this his";
let pattern = /^Is/g;

Try it yourself

Example 2

Perform a global, case-insensitive multi-line search for "is" at the beginning of each line:

let text = `Is this
all there
is`
let pattern = /^is/gmi;

Try it yourself

Syntax

new RegExp("^n")

Or abbreviated as:

/^n/

Modified syntax

new RegExp("^n"g")

Or abbreviated as:

/\^n/g

Browser Support

/^n/ Is ECMAScript1 (ES1) feature.

All browsers fully support ES1 (JavaScript 1997):

Chrome IE Edge Firefox Safari Opera
Support Support Support Support Support Support