in reply to Find duplicate digits
Because I use the /g, the second match continues after the first one, so its capture group will actually be the 2nd occurrence of the digit. Then the backreference would be the third (which would mean we don't want it).#! perl use strict; use warnings; while (<DATA>) { print if /(\d)(?=.*\1)/g and not /($1)(?=.*\1)/g; } __DATA__ 0000 (Don't pick) 0001 (Don't pick) 0012 (Pick) 0011 (Pick) 1001 (Pick) 1009 (Pick) 1234 (Don't pick) 9879 (Pick)
It would not work for situations where some digit appears three times but another appears only twice (so it would be a "pick"). But since your examples are only four digits long, that doesn't come up here.
|
|---|