Note that split passes through the original string if the split pattern never matches. This condition should probably be checked if not wanted.
>perl -wMstrict -le "my $orf = 'AAAAXXAAAAAXXAAAAAXPXAAA'; my @digested0 = split /(?<=[KR](?!P))/, $orf; print for @digested0; " AAAAXXAAAAAXXAAAAAXPXAAA
Here's an m// solution without this drawback:
>perl -wMstrict -le "my $a = 'AAAAXRXAAAAAXKXAAAAAXRPXAAA'; my $cut = qr{ [KR] (?!P) }xms; my $digest = qr{ .*? $cut | (?<= $cut) .* \z }xms; my @digested = $a =~ m{ $digest }xmsg; print qq{'$_'} for @digested; $a = 'AAAXXXPPPAAAXXXAAAPPPAAA'; @digested = $a =~ m{ $digest }xmsg; print '@digested empty' unless @digested; " 'AAAAXR' 'XAAAAAXK' 'XAAAAAXRPXAAA' @digested empty
In reply to Re: Splitting string (regex) while keeping the separator?
by AnomalousMonk
in thread Splitting string (regex) while keeping the separator?
by Cantello
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |