PDA

View Full Version : A little help on Regular Expressions


frodo
10-22-2002, 06:51 PM
Hello all.

I have a variable ($sch_body_file) in my perl script which holds the contents of a html page. All links in this html page have double quotes (") at the end of the URL. For example

<A href=http://www.cokama.com/" target=_blank>a link to cokama</A>

Basically I need to strip the ending doublequote from all strings which begin with href=http://

The resulting code should look like
<A href=http://www.cokama.com/ target=_blank>a link to cokama</A>

Bearing in mind also there could be multiple links in the HTML page. Unfortunatly I'm not that good at regular expressions so if anybody can help, I would appreciate it.

Cormac.

Astro-Boy
10-25-2002, 09:09 AM
Give this a whirl:

$sch_body_file =~ s~(href=http://[^"]+)"~$1~g;

- Mark

frodo
10-25-2002, 10:45 AM
That is perfect... worked a treat first time.

Thanks very much for your help, you've saved me hours of work!