Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

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:

[^some_char]some_char

than:

.*?some_char

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

In reply to Re: SOLVED:Regular expression fetching multiple matches by 7stud
in thread SOLVED:Regular expression fetching multiple matches by ansh batra

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others about the Monastery: (6)
    As of 2014-08-31 07:46 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The best computer themed movie is:











      Results (294 votes), past polls