Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Escapes within double quotes can be tricky. I suspect what you want is one of the following:

$regex = "href\\s*=\\s*\".*?\""; $regex = 'href\s*=\s*".*?"';

It might help you to print $regex and $match, to see what you are getting.

update: You can use $match in the substitution (at least it worked fine in my tests) but it won't do what you expect if $regex isn't what you expect. Also, since $match is one particular match, adding the global qualifier to the substitution using $match isn't likely to replace multiple instances.

You have indicated that you have more to do than just substitute the href values in the anchors. Without knowing more about what you are doing it is hard to make an appropriate recommendation but something like the following might be closer to what you want:

use strict; use warnings qw( FATAL all ); my $regex = 'href\s*=\s*".*?"'; print "regex = $regex\n"; foreach my $line (<DATA>) { chomp($line); while ($line =~ /$regex/) { my $match = $&; $line =~ s/$match/xxx/; } } __DATA__ No anchors here <a href="asdf">go there</a> <a href="fdsa">go here</a>

In reply to Re: Link Parser, something to be desired? by ig
in thread Link Parser, something to be desired? by koolgirl

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (6)
As of 2024-03-29 09:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found