in reply to Regex to only show 2nd character of the same character in a string
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
|
|---|
| 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 |