CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Regular Expressions:
Multiple matching

 



melco
Novice

Jun 12, 2006, 1:44 PM

Post #1 of 5 (3073 views)
Multiple matching Can't Post

Hi!
i have

Code
my($digits) = "0123456789";


What regex could I use to receive array of digits like
$array[0] == 0
.
.
.
$array[9] == 9

Thank you.


KevinR
Veteran


Jun 12, 2006, 5:14 PM

Post #2 of 5 (3071 views)
Re: [melco] Multiple matching [In reply to] Can't Post

I think this is what you are after:


Code
my($digits) = "0123456789"; 
my @array = split(//,$digits);


using split() with no argument in the regexp splits the string on each character.
-------------------------------------------------


melco
Novice

Jun 12, 2006, 11:25 PM

Post #3 of 5 (3070 views)
Re: [KevinR] Multiple matching [In reply to] Can't Post

Nop, it was not question about split syntax.
It's about Regexp and it was simple situation...
Really i have more complex task.
I have

Code
my $str = "melco@yandex.ru,(fred,barney,tom)@domain.com,juice@some.co.uk,..........,(email_N,email_N_plus_1)@domain2.com,somemail_N_plus_2@something.net"


I need to split it to:


Code
$a[0] = "melco@yandex.ru" 
$a[1] = "(fred,barney,tom)@domain.com"
$a[2] = "juice@some.co.uk"
.....
$a[$n] = "(email_N,email_N_plus_1)@domain2.com"
$a[$n+1] = "somemail_N_plus_2@something.net"

This is my real task.
Sorry for my wrong first question Crazy

Thank you all! Wink


rork
User

Jun 13, 2006, 2:39 AM

Post #4 of 5 (3067 views)
Re: [melco] Multiple matching [In reply to] Can't Post

You can use g to match more then once and an array to capture the results:

Code
my @res = $str =~ /regexp/g;


Hardest thing would be to make that regexp because emailaddresses can take many forms and I don't know if you can use Regexp::Common::Email::Adress because of the (name,name,name)@domain.com

A good source for more info about creating regular expressions is perlreref
--
Don't reinvent the wheel, use it, abuse it or hack it.


melco
Novice

Jun 13, 2006, 2:44 AM

Post #5 of 5 (3066 views)
Re: [rork] Multiple matching [In reply to] Can't Post

Big thank you, rork! Wink

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives