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

: \1, \2 - JavaScript | MDN

MDN Web Docs

View in English Always switch to English

: \1, \2

Baseline

20157

regex
\N

: N

N

1 \1 2 \2 \0 NUL

js
/(b)\1/i.test("bB"); // true

js
/(a)\2/u; // SyntaxError: Invalid regular expression: Invalid escape

Unicode 8

js
/(a)\2/.test("a\x02"); // true

js
/(?:a|(b))\1c/.test("ac"); // true
/\1(a)/.test("a"); // true

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"

\w

js
function findDuplicates(text) {
  return text.match(/\b(\w+)\s+\1\b/i)?.[1];
}

findDuplicates("foo foo bar"); // 'foo'
findDuplicates("foo bar foo"); // undefined
findDuplicates("Hello hello"); // 'Hello'
findDuplicates("Hello hellos"); // undefined

ECMAScript 2027 LanguageSpecification
# prod-DecimalEscape


Web Proxy Viewer  |  New URL  |  Original Page