in reply to want regex to find 2nd and 3rd occurence of a character
This sounds like it might be a job for List::MoreUtils:
use strict; use warnings; use List::MoreUtils qw(natatime); my $str="AJKDHAKAESRADADKLASRRASDASDKASEKA"; my @ar = split '(?<=[KR](?!P))', $str; #to split where i ever i see a +K or R. print "ar: @ar\n"; my @new; my $it = natatime 2, @ar; while (my @vals = $it->()) { push @new, (join '', @vals); } print "new: @new\n";
prints:
ar: AJK DHAK AESR ADADK LASR R ASDASDK ASEK A new: AJKDHAK AESRADADK LASRR ASDASDKASEK A
Is that what you are looking for for question #1? If so, I think you can use the natatime function to also solve #2.
Update: OP has been updated.
Also, it is best if you just put code snippets inside <code> tags, rather than the bulk of your question.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: want regex to find 2nd and 3rd occurence of a character
by heidi (Sexton) on May 22, 2008 at 19:34 UTC |