| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Regular_expressions/Capturing_group | [Back] [Original] |
Get to know MDN better
(pattern)
RegExp.prototype.exec()String.prototype.match()String.prototype.matchAll() String.prototype.replace() String.prototype.replaceAll() replacement pN /(ab)|(cd)/.exec("cd"); // ['cd', undefined, 'cd']
/([ab])+/.exec("abc"); // ['ab', 'b']; because "b" comes after "a", this result overwrites the previous one
/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
/((a+)?(b+)?(c))*/.exec("aacbbbcac"); // ['aacbbbcac', 'ac', 'a', undefined, 'c']
3
"aac" "aa"undefined"c""bbbc" undefined"bbb""c""ac" "a"undefined"c"2 "bbb" 3 undefined
d exec() indices
YYYY-MM-DD
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])
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 |