A global search for "Is" at the beginning of a string:
let text = "Is this his";
let pattern = /^Is/g;
Try it Yourself »
The ^n quantifier matches any string with n at the beginning of it.
Tip: Use the n$ quantifier to match any string with n at the END of it.
/^n/
is an ECMAScript1 (ES1) feature.
ES1 (JavaScript 1997) is fully supported in all browsers:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | Yes |
new RegExp("^
n")
or
/^
n/
new RegExp("^
n", "g")
or simply:
/\^
n/g
A global, case-insensitive, multiline search for "is" at the beginning of each line:
let text = `Is this
all there
is`
let pattern = /^is/gmi;
Try it Yourself »
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!