What is a Perl regex for finding the first non-consecutively-repeating character in a string.
- by DVK
Your task, should you choose to accept it, is to write a Perl regular expression that for a given string, will return the first occurence of a character that is not consecutively duplicated. In other words, both preceded AND succeeded by characters different from itself (or start/end of string respectively).
Example:
IN: aabbcdecc
OUT: c
Please note that "not consecutively duplicated" does not mean "anywhere in the string".
NOTE: it must be a pure regex expression. E.g. the solution that obviously comes to mind (clone the string, delete all the duplicates, and print the first remaining character) does not count, although it solves the problem.
The question is inspired by my somewhat off-topic answer to this: http://stackoverflow.com/questions/2548606/perl-function-to-find-first-non-repeating-character-in-a-string