[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/RegExp/RegExp [Back]  [Original]

RegExp() - JavaScript | MDN

MDN Web Docs

View in English Always switch to English

RegExp()

20157

RegExp

JavaScript

const regex1 = /\w+/;
const regex2 = new RegExp("\\w+");

console.log(regex1);
// /\w+/

console.log(regex2);
// /\w+/

console.log(regex1 === regex2);
// false

js
new RegExp(pattern)
new RegExp(pattern, flags)
RegExp(pattern)
RegExp(pattern, flags)

pattern

ES5 RegExp RegExp

flags

flags

flags (lastIndex 0)( ES2015 )

flags flags( lastIndex )

flags

g

i

u Unicode

m

^ $*\n\r

s

.

uunicode

pattern Unicode

y

lastIndex

RegExp .

js
/ab+c/i;
new RegExp(/ab+c/, "i"); // 
new RegExp("ab+c", "i"); // 

new RegExp('ab+c') ()

ECMAScript 2027 LanguageSpecification
# sec-regexp-constructor


Web Proxy Viewer  |  New URL  |  Original Page