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:
But it's better to use module URIuse 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"; }
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 |