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

And just for variety (and also because this really *IS* the one way I can make OP's description make sense), do you mean you want to "show" the second char of each contiguously paired char?

That would be, in the example provided by salva, 'abccabbcabc', and used by several other respondents:

c   b

which this provides:

#!/usr/bin/perl use warnings; use strict; # 856624 my $str = 'abccabbcabc'; my @chars = split(//, $str); my $seen = '-'; for my $char(@chars) { if ($char =~ $seen ) { print $char . "\t|\t"; # skip the tabs and pipe if desired } else { $seen = $char; } } =head Output: c | b | =cut
  • Comment on Re: Regex to only show 2nd character of the same character in a string
  • Download Code

Replies are listed 'Best First'.
Re^2: Regex to only show 2nd character of the same character in a string
by ikegami (Patriarch) on Aug 24, 2010 at 14:51 UTC
    If you're right, then the following would do:
    my @chars = /(.)\1/sg;