| Author |
Extract digits from string
|
|
| John Wright 2006-09-05, 6:57 pm |
| Hi,
I have a data in a variable like
$data="book(18614)---book2.2(18616)---book3(18617)---book4(14432) ......... so on"
i want to store all digit value lying between ( ) into an array.
$array[0]=18614
$array[1]=18616
$array[2]=18617 ... so on
Can someone help please?
Thanks
---------------------------------
All-new Yahoo! Mail - Fire up a more powerful email and get things done faster.
| |
| Jeff Pang 2006-09-05, 6:57 pm |
| Hi,how about this?
my @array = $data =~ /\((\d+)\)/g;
-----Original Message-----
>From: john wright <join_perl@yahoo.com>
>Sent: Sep 5, 2006 11:29 AM
>To: beginners@perl.org
>Subject: Extract digits from string
>
>Hi,
> I have a data in a variable like
> $data="book(18614)---book2.2(18616)---book3(18617)---book4(14432) ......... so on"
> i want to store all digit value lying between ( ) into an array.
> $array[0]=18614
> $array[1]=18616
> $array[2]=18617 ... so on
>
> Can someone help please?
> Thanks
>
>
>---------------------------------
> All-new Yahoo! Mail - Fire up a more powerful email and get things done faster.
--
Jeff Pang
NetEase AntiSpam Team
http://corp.netease.com
| |
| Dr.Ruud 2006-09-05, 6:57 pm |
| john wright schreef:
> I have a data in a variable like
> $data="book(18614)---book2.2(18616)---book3(18617)---book4(14432)
> ......... so on" i want to store all digit value lying between (
> ) into an array. $array[0]=18614
> $array[1]=18616
> $array[2]=18617 ... so on
@array = $data =~ /\((\d+)\)/g ;
--
Affijn, Ruud
"Gewoon is een tijger."
| |
| J. Alejandro Noli 2006-09-09, 3:57 am |
| Jeff Pang <pangj@earthlink.net> writes:
> Hi,how about this?
>
> my @array = $data =~ /\((\d+)\)/g;
And what does this means ^^^^^^^^^^ ?
Thanks !
[color=darkred]
>
> -----Original Message-----
| |
| Andy Greenwood 2006-09-09, 3:57 am |
| start with the regex. It's going to look in $data for items that match
and return the elements caught by the ()'s into @array. the regex will
catch anything that:
1) starts with a (
2) is made up of at least 1 digit character
3) ends with a )
On 9/8/06, J. Alejandro Noli <alejandro@janoli.com.ar> wrote:
> Jeff Pang <pangj@earthlink.net> writes:
>
>
> And what does this means ^^^^^^^^^^ ?
>
> Thanks !
>
>
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
>
>
>
| |
| Juan Pablo Feria Gomez 2006-09-09, 3:57 am |
| > > my @array = $data =~ /\((\d+)\)/g;
>
> And what does this means ^^^^^^^^^^ ?
>
is not an ^, is / next to a \ (/\)
|
|
|
|