in reply to Creating a regex to match part of a URL's domain name (was: pattern matching)
This will work and allows domains like foo-bar to capture which using \w does not. This regex looks to the left of the .com and stops grabbing chars at the first dot or forward slash.
Also note that you assign to @i which is an array rather than $i which is a scalar and what you probably had in mind.
tachyon
my $i = "l-12345.in.some.domain.com/blargh/index.html"; my ($result) = $i =~ m|([^./]+)\.com|; print $result; # if you want to allow several endings like .com .gov etc my ($result) = $i =~ m#([^./]+)\.(?:com|org|gov|edu|etc)#;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: pattern matching
by strfry() (Monk) on Jun 06, 2001 at 18:36 UTC |