by Luuk » Thu Jul 28, 2022 10:07 pm
(Not digit) (19--or--20) (2-digits) 4-digits (Not digit)/all-matches
(?<!\d)(19|20)(\d\d)\d{4}(?!\d)/g
$1$2
(?<!\d) ----> To the left cannot be a digit
(19|20) ---> 19-or-20
(\d\d) -----> any 2-digits: 0-9
\d{4} ------> any 4-digits: 0-9 (same as \d\d\d\d)
(?!\d) -----> To the right cannot be a digit
/g ---------> Says global for all-matches, instead of 1st-match
The red (groups) is called look-arounds and they do only match conditions, without capturing any of the characters.
So this is why the $1 gets married to (19|20) for 'Group1', and the $2 gets married to (\d\d) for 'Group2'.
The \d{4} is not (grouped) because we dont need $3 to put the last 4-digits back into the filename.
You could always group it like (\d{4}) just to make the "Match" part look better for the eyesight.
But it still conducts exactly the same, unless adding something like --$3 into your "Replace".