in reply to Can you do an OR with a REGEXP

URL parsing is not so simple. You can write regexp for your case like this:

use strict; use warnings; my $str1 = 'http://hostname.company.com:80//directory/'; my $str2 = 'http://hostname.company.com:80//'; for ( $str1, $str2 ) { my ( $host, $dir ) = m{https?://([^:]+):\d+//(:?([^/]+)/)?}; print "Host: $host, Dir: ", ( defined($dir) ? $dir : 'undefined' ) +, "\n"; }
But it's better to use module URI

P.S.: btw, why there are two slashes?

Replies are listed 'Best First'.
Re^2: Can you do an OR with a REGEXP
by slaclnx (Initiate) on May 22, 2009 at 14:51 UTC
    I'm trying to parse a Juniper access log to gauge application usage. The two forward slashes are due to the Juniper logging. Kind of weird since that is the only part of the URL that it doubles the slashes. thanks slaclnx