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

RegExp.prototype.exec() - JavaScript | MDN

This page was translated from English by the community. Learn more and join the MDN Web Docs community.

View in English Always switch to English

RegExp.prototype.exec()

Baseline Widely available

This feature is well established and works across many devices and browser versions. Its been available across browsers since 2015 ..

exec() . null.

, , RegExp.prototype.test(), String.prototype.search().

In this article

regexObj.exec(str)

str

, .

, exec() . , , .

, exec() null.

:

js
//    , ,     ,
//     .     .
//   .
var re = /,\s().+?()/gi;
var result = re.exec(",  ,   ,  .");

:

/
result [0] . ,
[1], ...[n] , . . [1] =
[2] =
index , . 9
input . , , , .
re lastIndex , . "g", . 31
ignoreCase , "i". true
global , "g". true
multiline , "m". false
source . ,\s().+?()

:

"g", exec() . , str, lastIndex ( test() lastIndex). , , :

js
var myRe = /*/g;
var str = "";
var myArray;
while ((myArray = myRe.exec(str)) !== null) {
  var msg = " " + myArray[0] + ". ";
  msg += "     " + myRe.lastIndex;
  console.log(msg);
}

:

js
 .      3
 .      9

: ( RegExp) while; , lastIndex . , , .

: exec()

exec() RegExp:

js
var matches = /( \S+)/.exec("  !");
console.log(matches[1]);

!.

Specification
ECMAScript 2027 LanguageSpecification
# sec-regexp.prototype.exec


Web Proxy Viewer  |  New URL  |  Original Page