Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re: SOLVED:Regular expression fetching multiple matches

by 7stud (Deacon)
on Jan 09, 2013 at 08:16 UTC ( #1012405=note: print w/replies, xml ) Need Help??

in reply to SOLVED:Regular expression fetching multiple matches

Perl has so many ways of quoting things, you never have to escape characters.

1) Use the here doc syntax for your string, which will get rid of the outer double quote marks--allowing you to use double quote marks inside your string.

2) Use qr{ } around your whole regex, which will get rid of the beginning and ending forward slash marks(/)--which will allow you to use forward slash marks inside your regex.

3) Inside a regex, a single quote mark has no special meaning (same for a double quote mark), so you don't have to escape it.

4) It's usually more efficient to use:




Here is an example:

use strict; use warnings; use 5.012; my $string = <<END_OF_HTML; <ul> <li> <div id="Show1400"> <a href="../../../KeyboardKeys/RetainerClip/Acer/Aspire/1400">14 +00</a> </div> </li> <li> <div id="Show1410"> <a href="../../../KeyboardKeys/RetainerClip/Acer/Aspire/1410">14 +10</a> </div> </li> </ul> END_OF_HTML my $regex = qr{<a href=["']([^"']+)["']>[^<]+</a>}; while ($string =~ /$regex/g) { say $1; } --output:-- ../../../KeyboardKeys/RetainerClip/Acer/Aspire/1400 ../../../KeyboardKeys/RetainerClip/Acer/Aspire/1410

Replies are listed 'Best First'.
Re^2: SOLVED:Regular expression fetching multiple matches
by ansh batra (Friar) on Jan 10, 2013 at 11:28 UTC

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2016-10-25 06:14 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (315 votes). Check out past polls.