in reply to Re: Regex to only show 2nd character of the same character in a string
in thread Regex to only show 2nd character of the same character in a string

then...
my $str = 'abccabbcabc'; my %seen; while ($str =~ /(.)/g) { printf "character %s found at pos %d, reps %d\n", $1, pos($str), $ +seen{$1} if $seen{$1}++; }
  • Comment on Re^2: Regex to only show 2nd character of the same character in a string
  • Download Code

Replies are listed 'Best First'.
Re^3: Regex to only show 2nd character of the same character in a string
by AnomalousMonk (Archbishop) on Aug 23, 2010 at 12:57 UTC

    Yes, but is that what wtritchie really wants? That's what I'm still in the dark about, and likely to remain so until wtritchie throws some light on the subject.

    BTW: ikegami's guess (Update: anent UTF-16 or some such) seems like it might be somewhere near the ballpark; ikegami possesses a preternatural ability for making such guesses.

    Update: ikegami has withdrawn his first reply in its entirety, but I'd still be willing to bet a doughnut to a million computrons that something like his UTF-16 guess is not far wrong. But wtritchie holds the key to all this, and further wtritchie sayeth not.

      No, My solution is wrong. I missed the "same character" bit. I'll post again later.

      Well, it may or may not be “what the OP really wants,” but it seems to work, and in the end, IMHO, that’s what really matters most.

      We have a special subforum for “regex tricks,” and it's called:   “Obfuscated Code.” ;-)

      Seriously... the most important thing is that the code, whatever it is, is easy to understand, is reasonably efficient (not that such things really matter too much anymore), and is easily maintained.   When (not “if”) the requirements change (again), it ought to be the work of five minutes or less to change the code, and to be utterly confident that it works.   Anything more “clever” than that is always regrettable.