Re: regexp pipe problems..
- From: "A. Sinan Unur" <1usa@xxxxxxxxxxxxxxxxxxx>
- Date: Thu, 30 Jun 2005 07:02:54 GMT
willwade@xxxxxxxxx wrote in news:1120113362.085557.326410
@f14g2000cwb.googlegroups.com:
> OK, I have a "fairly" straightforward regular expression which grabs
> some bits out of a url. Now this should be easy but I can't see the
> wood for the trees. I have a few or's in there but it seems to be
> adding each to memory - when I only want the found one. Also - instead
> of matching just the subdomain it matches the whole domain ($1 see
> below) - whats that all about?
>
> $url = 'http://sub1.site3.org/slash/slashey2/slashey3/39/4/223';
>
> if ($url =~ m{(([^/]+).site1.org|([^/]+).site2.org|([^/]+).site3.org)
> /slash/slashey2/([^/]+)/([0-9]+)/([0-9]+)/([0-9a-zA-Z-]+)}){
I don't understand what exactly you are doing here, but are you, by any
chance, forgetting that dots are special in regular expressions?
> print "yay! $1,$2,$3,$4,$5";
> } else {
> print "poo";
> exit;
> }
>
> and it prints:
>
> yay! sub1.site3.org,,,sub1,
When I ran your code, it printed poo. Post the code you actually ran.
Please see the posting guidelines for this group to learn how you can
help yourself, and help others help you.
> when I want to print:
>
> yay! sub1,slashey3,39,4,223
#!/usr/bin/perl
use strict;
use warnings;
my $url = q{http://sub1.site3.org/slash/slashey2/slashey3/39/4/223};
if( $url =~ m{^http://
([[:alnum:]]+)
\..+ /
[[:alnum:]]+ /
[[:alnum:]]+ /
([[:alnum:]]+)/
([[:digit:]]+)/
([[:digit:]]+)/
([[:digit:]]+)$}x ) {
print join('|', $1, $2, $3, $4, $5)."\n";
} else {
print "did not match\n";
}
__END__
D:\Home> ttt
sub1|slashey3|39|4|223
See perldoc perlre for explanations.
Sinan
--
A. Sinan Unur <1usa@xxxxxxxxxxxxxxxxxxx>
(reverse each component and remove .invalid for email address)
comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
.
- References:
- regexp pipe problems..
- From: willwade
- regexp pipe problems..
- Prev by Date: regexp pipe problems..
- Next by Date: Copy local Groups -- Get SID
- Previous by thread: regexp pipe problems..
- Next by thread: Re: regexp pipe problems..
- Index(es):
Relevant Pages
|