[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Regular_expressions/Capturing_group [Back]  [Original]

: (...) - JavaScript | MDN

MDN Web Docs

View in English Always switch to English

: (...)

Baseline

20157

regex
(pattern)

pattern

JavaScript

12 2

: exec() 12 0`` \0` NUL

js
/(ab)|(cd)/.exec("cd"); // ['cd', undefined, 'cd']

js
/([ab])+/.exec("abc"); // ['ab', 'b']; because "b" comes after "a", this result overwrites the previous one

js
/c(?=(ab))/.exec("cab"); // ['c', 'ab']
/(?<=(a)(b))c/.exec("abc"); // ['c', 'a', 'b']
/(?<=([ab])+)c/.exec("abc"); // ['c', 'a']; because "a" is seen by the lookbehind after the lookbehind has seen "b"

undefined

js
/((a+)?(b+)?(c))*/.exec("aacbbbcac"); // ['aacbbbcac', 'ac', 'a', undefined, 'c']

3

  1. "aac" "aa"undefined"c"
  2. "bbbc" undefined"bbb""c"
  3. "ac" "a"undefined"c"

2 "bbb" 3 undefined

d exec() indices

? ? (

YYYY-MM-DD

js
function parseDate(input) {
  const parts = /^(\d{4})-(\d{2})-(\d{2})$/.exec(input);
  if (!parts) {
    return null;
  }
  return parts.slice(1).map((p) => parseInt(p, 10));
}

parseDate("2019-01-01"); // [2019, 1, 1]
parseDate("2019-06-19"); // [2019, 6, 19]

title='xxx' title="xxx" 2 ([2])

js
function parseTitle(metastring) {
  return metastring.match(/title=(["'])(.*?)\1/)[2];
}

parseTitle('title="foo"'); // 'foo'
parseTitle("title='foo' lang='en'"); // 'foo'
parseTitle('title="Named capturing groups\' advantages"'); // "Named capturing groups' advantages"

ECMAScript 2027 LanguageSpecification
# prod-Atom


Web Proxy Viewer  |  New URL  |  Original Page