Re: regexp pipe problems..



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
.



Relevant Pages

  • Re: Basic Regular Expressions question...
    ... this program should take the long string in $find ... > being treated as a Regular Expression but I can't figure out a way to ... posting guidelines for this group if you haven't already done so. ... Sinan Unur ...
    (comp.lang.perl.misc)
  • Re: need to negate regex in middle of expression
    ... > i need a regular expression that will allow me to search for the ... Look for modules related to parsing HTML. ... please consult the posting guidelines for this group ... Sinan Unur ...
    (comp.lang.perl.misc)
  • Re: Basic Regular Expressions question...
    ... Sinan Unur wrote: ... >> To my understanding, this program should take the long string in ... >> being treated as a Regular Expression but I can't figure out a way ... > posting guidelines for this group if you haven't already done so. ...
    (comp.lang.perl.misc)
  • Re: Regular expression question.
    ... > Tad McClellan wrote in message ... >>> I am trying to write a regular expression that extracts all the log ... It works with the input record seperator. ... Sinan Unur ...
    (comp.lang.perl.misc)
  • Re: Regexp question...
    ... > I wanted a regular expression to seperate a filename from a full path ... Sinan Unur ...
    (comp.lang.perl.misc)