Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: reg exp question

by quester (Vicar)
on Jul 29, 2009 at 09:35 UTC ( #784188=note: print w/replies, xml ) Need Help??


in reply to reg exp question

Since no one seems to have mentioned it so far...

The basic problem here is greedy matching. The ".*" is a greedy match so "m%(<a href="http://dynamodata.*/a>)%g" will match exactly once, with ".*" matching everything between the first occurrence of "<a href="http://dynamodata" and the last occurrence of "/a>". If, as in this case, you want to match the first following occurrence of "/a>" you can use the non-greedy form ".*?". So,
@tags = $content =~ m%(<a href="http://dynamodata.*?/a>)%g;
should work (not tested, since I'm not at the right machine at the moment....)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://784188]
help
Chatterbox?
[shmem]: moin monkses
[Discipulus]: good morning shmem
[Discipulus]: test for pmcbtk
[Discipulus]: sometimes the client dies for extra content </chatter><span class="error" style="color: #cc0000">Server Error (Error ID 9162

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (12)
As of 2017-07-25 08:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I came, I saw, I ...
























    Results (364 votes). Check out past polls.