Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Regexps to change HTML tags/attributes

by Abigail-II (Bishop)
on Aug 27, 2003 at 16:04 UTC ( [id://287077]=note: print w/replies, xml ) Need Help??


in reply to Regexps to change HTML tags/attributes

There's much wrong with your program. First, if you are going to modify the file line-by-line, it's a total waste to first read in all lines into an array. However, when dealing with HTML, it's wrong to look at individual lines. HTML does not have a concept of lines, and tags can have newlines inside them.

As for the regexes, the first pattern will not do the right thing if there's another tag at the same line. The second pattern will fail to do the right thing if the anchor has another attribute before "HREF", or if it has an attribute value containing a ">".

You would be far better off using one of the many HTML parsing modules found on CPAN.

Abigail

  • Comment on Re: Regexps to change HTML tags/attributes

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2024-04-25 07:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found