while ( <DATA> )
{
if ( /browse(\/.*)\// ) { #if the current $_ matches
#browse followed by a
# / followed by anything
#but having to be followed by
# another /
#then put whatever was found
#between the parens in $line
my $line = $1;
print "$line\n";
}
}
__DATA__
http://www.url.com/browse/ASP/scripts/homesites/
/browse/ASP/scripts/homesites/
/browse/ASP/scripts/homesites/index.htm
I don't know if you noticed but in your original post browse was misspelled.
-Enlil | [reply] [d/l] |
while ( <DATA> )
{
if ( /browse(\/.*\/)/ ) { #if the current $_ matches
#browse followed by a
# / followed by anything
#but having to be followed by
# another /
#then put whatever was found
#between the parens in $line
my $line = $1;
print "$line\n";
}
}
__DATA__
http://www.url.com/browse/ASP/scripts/homesites/
/browse/ASP/scripts/homesites/
/browse/ASP/scripts/homesites/index.htm
I meant to put the last \/ inside the parens as you wanted the final / included in the match at the end of the returned string. My mistake. -Enlil | [reply] [d/l] |
my ($match) = $a =~ m!(/browse.*/)!;
Use that and $match will contain the slash prior to "browse" and everything following up to and including the final slash.
Be forewarned, that will break if you give it a string ending in a directory that you want to match but which doesn't have a slash. The string 'http://foo.bar.com/some/path/browse/ASP/scripts', for example, would cause $match to be set to '/browse/ASP/'. If that's alright, then great. If not, they you have to find another way of distinguising a file and a directory. (Perhaps all of your files contain a dot and none of your directories do.)
-sauoq
"My two cents aren't worth a dime.";
| [reply] [d/l] [select] |
Well, everything after browse and everything before the last "/"
can be also like this
$a =~ s|/browse(.*/)|$1|i;
Comment: Ooops! Too late! It's like hiseldl
Hopes
perl -le '$_=$,=q,\,@4O,,s,^$,$\,,s,s,^,b9,s,$_^=q,$\^-]!,,print'
| [reply] [d/l] [select] |