| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Global_Objects/RegExp | [Back] [Original] |
Get to know MDN better
This page was translated from English by the community. Learn more and join the MDN Web Docs community.
This feature is well established and works across many devices and browser versions. Its been available across browsers since 2015 ..
* Some parts of this feature may have varying levels of support.
RegExp .
, , JavaScript.
const regex1 = /\w+/;
const regex2 = new RegExp("\\w+");
console.log(regex1);
// Expected output: /\w+/
console.log(regex2);
// Expected output: /\w+/
console.log(regex1 === regex2);
// Expected output: false
, :
/pattern/flags new RegExp(pattern, flags)
RegExp: . , - . :
/ab+c/i;
new RegExp("ab+c", "i");
. . , , , .
, , new RegExp('ab+c'), . -, , , , .
- ( \). , :
var re = /\w+/;
var re = new RegExp("\\w+");
. |
(, )
:
,
, |
|
\d |
.
, |
|
\D |
,
.
, |
|
\w |
-
, .
, |
|
\W |
,
, .
, |
|
\s |
,
, , ,
.
, |
|
\S |
, .
, |
|
\t |
. | |
\r |
. | |
\n |
. | |
\v |
. | |
\f |
. | |
[\b] |
(
\b).
|
|
\0 |
. . | |
\cX
|
, |
|
\xhh
|
hh (
).
|
|
\uhhhh
|
hhhh ( ).
|
|
\ |
, , , .
,
, , , .
, * ,
;
|
|
[xyz] |
. . .
, |
|
[^xyz] |
. , . .
, |
|
^ |
c . , .
, |
|
$ |
c . , .
, |
|
\b |
,
(
, |
|
\B |
- , .
, |
|
(x) |
, . , ( ). |
|
\n
|
, |
|
(?:x) |
x, . .
[1], ..., [n]
$1, ..., $9
RegExp.
|
|
x*
|
x .
, |
|
x+
|
x
.
, |
|
x*?x+?
|
x
, |
|
x?
|
x .
,
-
|
|
x(?=y)
|
x, x y. , /(?=)/
.
/(?=|)/
. ,
, .
|
|
x(?!y)
|
|
|
(?<=y)x
|
, / |
|
(?<!y)x
|
|
|
x|y
|
, |
|
x{n}
|
, |
|
x{n,}
|
, |
|
x{n,m}
|
, |
|
RegExp.
RegExp.length RegExp.length 2.
RegExp , , .
var re = /(\w+)\s(\w+)/;
var str = "John Smith";
var newstr = str.replace(re, "$2, $1");
console.log(newstr);
//
var re = /([-]+)\s([-]+)/i;
var str = " ";
var newstr = str.replace(re, "$2, $1");
console.log(newstr);
Smith, John ,
(Unix, Windows ). .
var text = " \n \r\n \r ";
var lines = text.split(/\r\n|\r|\n/);
console.log(lines); // [ ' ', ' ', ' ', ' ' ]
, .
var s = "Please yes\nmake my day!";
s.match(/yes.*day/);
// null
s.match(/yes[^]*day/);
// 'yes\nmake my day'
, .
var text = " \n ";
var regex = /(\S+) \n?/y;
var match = regex.exec(text);
console.log(match[1]); // ''
console.log(regex.lastIndex); // '14'
var match2 = regex.exec(text);
console.log(match2[1]); // ''
console.log(regex.lastIndex); // '27'
var match3 = regex.exec(text);
console.log(match3 === null); // 'true'
, , try { } catch { }. eval(), RegExp(-, --) ( // , , catch). :
var supports_sticky;
try {
RegExp("", "y");
supports_sticky = true;
} catch (e) {
supports_sticky = false;
}
console.log(supports_sticky); // 'true'
, \w \W ASCII; , a z, A Z, 0 9 _. , , , \uhhhh, hhhh , . , , .
var text = " text ";
var regex = /[\u0400-\u04FF]+/g;
var match = regex.exec(text);
console.log(match[0]); // ''
console.log(regex.lastIndex); // '7'
var match2 = regex.exec(text);
console.log(match2[0]); // '' [ 'text']
console.log(regex.lastIndex); // '15'
//
var url = "http://xxx.domain.com";
console.log(/[^.]+/.exec(url)[0].substr(7)); // 'xxx'
| Specification |
|---|
| ECMAScript 2027 LanguageSpecification # sec-regexp-regular-expression-objects |
Gecko 34, , , undefined :
// Firefox 33
"x".replace(/x(.)?/g, function (m, group) {
console.log("'group:" + group + "'");
}); // 'group:'
// Firefox 34
"x".replace(/x(.)?/g, function (m, group) {
console.log("'group:" + group + "'");
}); // 'group:undefined'
, , RegExp.$N - undefined (bug 1053944).
This page was last modified on 29 . 2026 . by MDN contributors.
RegExpObject/FunctionObject.prototype.__defineGetter__()Object.prototype.__defineSetter__()Object.prototype.__lookupGetter__()Object.prototype.__lookupSetter__()Object.prototype.hasOwnProperty()Object.prototype.isPrototypeOf()Object.prototype.propertyIsEnumerable()Object.prototype.toLocaleString()Object.prototype.toString()Object.prototype.valueOf()Your blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |