Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

regular expressions for url

Status
Not open for further replies.

danny2785

Programmer
Jun 26, 2006
16
0
0
US
I am trying to grab the url without the protocol or the www. For example if you have http: I just want google.com. I am currently using $line =~ /[^\n\r]+.(?=[\s\.,])/ Can anybody give me some suggestions? Thanks
 
If it is _only_ the protocol and " that you wish to strip:
Code:
while(<DATA>) {
  my ($field) = m#(?:[^:]://(?:[URL unfurl="true"]www\.)?)(.*)#;[/URL]
  print "[$field]\n";
}
__DATA__
[URL unfurl="true"]http://www.google.com[/URL]
[URL unfurl="true"]http://www.tek-tips.com/viewthread.cfm?qid=1247777&page=1[/URL]
[URL unfurl="true"]http://www.perl.com[/URL]
[URL unfurl="true"]http://perl.com/index.html[/URL]
[URL unfurl="true"]http://somethingotherthanwww.perl.com[/URL]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top