/\k/.test("k"); // trueNamed backreference: \k<name> / notebook
Named backreference: \k<name>
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.
function parseTitle(metastring) {
return metastring.match(/title=(?<quote>["'])(.*?)\k<quote>/)[2];
}
parseTitle('title="foo"'); // 'foo'
parseTitle("title='foo' lang='en'"); // 'foo'
parseTitle('title="Named capturing groups\' advantages"'); // "Named capturing groups' advantages"