Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > RExp matchs many times,how can i get the matched content?

Reply
Thread Tools

RExp matchs many times,how can i get the matched content?

 
 
firenet
Guest
Posts: n/a
 
      07-25-2006
#!/usr/bin/perl -w
undef $/;
$buf=<>;
print foreach($buf =~/<img>(.*?)<\/img>/sg);

By the program above , i can print the content i wanted;but i want to
get it directly.
What should i do? Thanks.

 
Reply With Quote
 
 
 
 
firenet
Guest
Posts: n/a
 
      07-25-2006
thanks a lot. i'm newbie for perl , so i didn't recognize that is a
array.
Aukjan van Belkum wrote:
> firenet wrote:
>
> > print foreach($buf =~/<img>(.*?)<\/img>/sg);

>
> my @array = ($buf =~/<img>(.*?)<\/img>/sg);
>
> > By the program above , i can print the content i wanted;but i want to
> > get it directly.

>
> You are traversing an array with 'foreach', you should have then noticed
> that you could also just assing this array to another array...
>
> Aukjan


 
Reply With Quote
 
 
 
 
Ben Morrow
Guest
Posts: n/a
 
      07-25-2006

Quoth Aukjan van Belkum <(E-Mail Removed)>:
> firenet wrote:
>
> > print foreach($buf =~/<img>(.*?)<\/img>/sg);

>
> my @array = ($buf =~/<img>(.*?)<\/img>/sg);
>
> > By the program above , i can print the content i wanted;but i want to
> > get it directly.

>
> You are traversing an array with 'foreach', you should have then noticed
> that you could also just assing this array to another array...


It's not an array, it's a list.

Ben

--
The cosmos, at best, is like a rubbish heap scattered at random.
Heraclitus
http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
anno4000@radom.zrz.tu-berlin.de
Guest
Posts: n/a
 
      07-26-2006
Aukjan van Belkum <(E-Mail Removed)> wrote in comp.lang.perl.misc:
> Ben Morrow wrote:
>
> >
> > It's not an array, it's a list.
> >

> ok: s/array/list/gs


The /s modifier has no effect, it shouldn't be there.

Anno
 
Reply With Quote
 
Tad McClellan
Guest
Posts: n/a
 
      07-26-2006
Aukjan van Belkum <(E-Mail Removed)> wrote:
> Ben Morrow wrote:
>
>>
>> It's not an array, it's a list.
>>

> ok: s/array/list/gs

^
^

A useless use of a regex modifier.

s/array/list/g


--
Tad McClellan SGML consulting
(E-Mail Removed) Perl programming
Fort Worth, Texas
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: get the matched regular expression position in string. Vlastimil Brom Python 0 09-03-2012 11:36 AM
Re: get the matched regular expression position in string. Chris Rebert Python 0 09-03-2012 08:36 AM
Re: get the matched regular expression position in string. Mark Lawrence Python 0 09-03-2012 08:33 AM
Can python read up to where a certain pattern is matched? Anthony Liu Python 3 03-07-2004 10:35 PM
MySQLdb -- any way to get "rows matched"? Chris Stromberger Python 5 09-03-2003 01:04 AM



Advertisments