The character class in your second example doesn't include ':' among the permitted characters, and this stops it being able to match the original duplicated substring. As a result it walks through the string looking for a duplicate that it can match, and 'd: d' is the first one it finds.
To match the initial duplicate with the character class, add the colon to the character class:
s/([:()\w\s-]+): \1/$1/;
Hugo
In reply to Re: Understanding regex
by hv
in thread Understanding regex
by Hena
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |