Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: want regex to find 2nd and 3rd occurence of a character

by toolic (Bishop)
on May 22, 2008 at 19:15 UTC ( [id://688022]=note: print w/replies, xml ) Need Help??


in reply to want regex to find 2nd and 3rd occurence of a character

I agree with moritz in that you might want to use another approach now that you have your string split into an array.

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
    hi toolic... THATS BRILLIANT....thank you so much... its working perfect... Amazing .... cool module. i will start using it efficiently !!! Perl monks rocks :) Thanks :)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://688022]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-04-24 19:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found