CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Regular Expressions:
Regular expression to match URLs?

 



laredotornado
New User

Nov 10, 2010, 1:07 PM

Post #1 of 2 (2162 views)
Regular expression to match URLs? Can't Post

Hi,

I'm using Perl 5.8.6 on Mac 10.6.3. Does anyone have a regular expression that can match URLs ? My ultimate goal is to take a text file, and replace the URLs with the anchor tag (in which the matched URL would be present in the "href" attribute).

Thanks, - Dave


Zhris
Enthusiast

Nov 11, 2010, 7:18 AM

Post #2 of 2 (2135 views)
Re: [laredotornado] Regular expression to match URLs? [In reply to] Can't Post

Hi,

If the URL's you are searching for lie inside href tags, then you could use an expression like:


Code
my $anchor = 'myanchor'; 
$html =~ s/(href\=\")([^\"]*)(\")/$1$anchor$3/ig;


If the "text file" you described is a HTML document, then it would be better to use a module such as HTML::Parser to perform the task you outlined.

Chris

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives