This would work, for example:
foreach(@array) {
$_ =~ s/(\w)\1/XY/g;
print "$_ "; # --> dXYmon jXYz stXYr cXYXYar XYXYb XYXYXYXYXY
+b
}
| [reply] [d/l] |
Thanks, this one works :)
| [reply] |
Based on the description given in the OP, almut has given the "right answer", but Corion has asked the right question, because the OP code seems to bear no relation to the description of the task, and it has some problems.
The s/// operation in your code contains only one set of parens in the regex match, but uses $2 in the replacement, which will always be an empty string. There's no mention of "XY" in the replacement. And given this type of regex pattern:
/(\w+)\1+/
strings that will match it include: "aa", "abab", "ababab", "abcabc", "abcabcabc", "abcdabcd", etc. -- that is, whenever any string of one or more letters is repeated one or more times -- but there will be quirks: "abababab" will be matched as "abab" occurring twice (not "ab" occurring four times).
| [reply] [d/l] |
Can you please explain in the code you used what the substitution is doing and how it relates to the goal you're trying to achieve?
Also, please show how the code you posted "works for a few" (examples?) and how it doesn't for bbbbbbbbbbbb.
| [reply] [d/l] |