Hmm, its interesting. My first thought would be - your separator will always be an odd number, so you can simply discard any elements with an odd number.
Is something like this possible ?:
my %s = (split (/([[:alpha:]])\1+/, '123aaaa23a3'), '' ); print Dumper \%s;
This will give you:
$VAR1 = { '23a3' => '', '123' => 'a' };
So you can extract your template through keys .
Unfortunately, my second approach of "selecting" pattern matches through %+ does not particularly help (separation does not fill in regular expression stuff).
But something like this:
my @delims ='123aaaa23a3' =~ m/(?<delim>[[:alpha:]])\g{delim}+/g; print Dumper \%+;
Using the named capture, we identify that a is from the capture group. Unfortunately, this does not look like padding when you do it through split - which can lead to a two-pass approach.
This is the closest I got:
#!/usr/bin/env perl use strict; use warnings; use Data::Dumper; my $str = '123aaaa23a3';
First, we process the string to extract character patterns of โ2 or moreโ to set as our dividers. Then we collect the regular expression from them using non-capture, so we can split.
Sobrique
source share