Let's remember how we used capturing groups in a regular expression itself:
let res = str.replace(/([a-z])\1/g, '!');
Sometimes there are situations when it is more convenient to refer to a capturing group not by its number, but by its name. To do this, we need to give the capturing group a name:
let res = str.replace(/(?<letter>[a-z])/g, '!');
Now we can access to this capturing
group with the syntax \k<name>
,
like this:
let res = str.replace(/(?<letter>[a-z])\k<letter>/g, '!');
Given a string:
let str = '12:59:59 12:59:12 09:45:09';
Find all substrings with time where an hour is the same as a second.