For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > January 2007 > regexp









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author regexp
Oryann9

2007-01-31, 6:59 pm

In this regexp

my $regexp = qr/(\d+\x3a1108
|\w+\x3a1108{1,} ) /;

vs.

my $regexp1 = qr/(\d+\x3a1108
|\w+\x3a1108){1,} /;

does the {1,} construct outside the parens () mean the entire string 1 or more times and within the parens mean only the last string \x3s1180 1 or more times?

What is the diff?

thank you.


---------------------------------
Don't pick lemons.
See all the new 2007 cars at Yahoo! Autos.
Rob Coops

2007-01-31, 6:59 pm

Number one will match:
\d+\x3a1108
or
\w+\x3a1108 at least once

Number two will match:
(\d+\x3a1108|\w+\x3a1108) at least once

so yes the {1,} outside means the whole thing and {1,} inside means only the
part after the or (pipe '|' sign) unless my regex skills are completely
deserting me after a whole day of work...

Regards,

Rob

On 1/31/07, oryann9 <oryann9@yahoo.com> wrote:
>
> In this regexp
>
> my $regexp = qr/(\d+\x3a1108
> |\w+\x3a1108{1,} ) /;
>
> vs.
>
> my $regexp1 = qr/(\d+\x3a1108
> |\w+\x3a1108){1,} /;
>
> does the {1,} construct outside the parens () mean the entire string 1 or
> more times and within the parens mean only the last string \x3s1180 1 or
> more times?
>
> What is the diff?
>
> thank you.
>
>
> ---------------------------------
> Don't pick lemons.
> See all the new 2007 cars at Yahoo! Autos.
>


nobull67@gmail.com

2007-01-31, 6:59 pm

On Jan 31, 4:04 pm, orya...@yahoo.com (Oryann9) wrote:
> In this regexp
>
> my $regexp = qr/(\d+\x3a1108
> |\w+\x3a1108{1,} ) /;
>
> vs.
>
> my $regexp1 = qr/(\d+\x3a1108
> |\w+\x3a1108){1,} /;
>
> does the {1,} construct outside the parens () mean the entire string 1 or more times


Yes, {1,} is just a long-winded way of saying +

> and within the parens mean only the last string \x3s1180 1 or more times?


No, not the whole string, just the last character, which is 8 (not 0
because the string is \x3a1108 not \x3s1180).

John W. Krahn

2007-01-31, 6:59 pm

oryann9 wrote:
> In this regexp
>
> my $regexp = qr/(\d+\x3a1108
> |\w+\x3a1108{1,} ) /;
>
> vs.
>
> my $regexp1 = qr/(\d+\x3a1108
> |\w+\x3a1108){1,} /;
>
> does the {1,} construct outside the parens () mean the entire string 1
> or more times and within the parens mean only the last string \x3s1180
> 1 or more times?
>
> What is the diff?


Modifiers affect the preceding character or grouping so in the first example
the modifier is attached to the character '8' and in the second example the
modifier is attached to the parentheses which will affect the entire contents
of the enclosing parentheses.

Also note that \d is a subset of \w so anything that matches \w will also
match \d.


John
--
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order. -- Larry Wall
Oryann9

2007-01-31, 6:59 pm



"John W. Krahn" <krahnj@telus.net> wrote: oryann9 wrote:
> In this regexp
>
> my $regexp = qr/(\d+\x3a1108
> |\w+\x3a1108{1,} ) /;
>
> vs.
>
> my $regexp1 = qr/(\d+\x3a1108
> |\w+\x3a1108){1,} /;
>
> does the {1,} construct outside the parens () mean the entire string 1
> or more times and within the parens mean only the last string \x3s1180
> 1 or more times?
>
> What is the diff?


Modifiers affect the preceding character or grouping so in the first example
the modifier is attached to the character '8' and in the second example the
modifier is attached to the parentheses which will affect the entire contents
of the enclosing parentheses.

Also note that \d is a subset of \w so anything that matches \w will also
match \d.


John
--

ok did not know the subset info.
thx agn!





---------------------------------
Looking for earth-friendly autos?
Browse Top Cars by "Green Rating" at Yahoo! Autos' Green Center.
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com