For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > August 2005 > class regex









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 class regex
Brent Clark

2005-08-29, 3:55 am

Hi list

I have im trying to enhance my regex skill.

My questions is, would

m/^p11[016]/io

match like

m/^(p110|p111|p116)/io

Any tips or advice, would greatfully be appreciated.

Kind Regards
Brent Clark
Charles K. Clarkson

2005-08-29, 7:55 am

Brent Clark <mailto:bclark@eccotours.dyndns.org> wrote:

: I have im trying to enhance my regex skill.
:
: My questions is, would
:
: m/^p11[016]/io
:
: match like
:
: m/^(p110|p111|p116)/io

Yes.


: Any tips or advice, would greatfully be appreciated.

Why not test you regex to see if it works? Asking
questions here will take much more time than testing.


foreach my $value ( @list_of_test_values ) {

print qq($value matches "m/^(p110|p111|p116)/io"\n)
if $value =~ m/^(p110|p111|p116)/io;

print qq($value matches "m/^p11[016]/io"\n)
if $value =~ m/^p11[016]/io;

}


HTH,

Charles K. Clarkson
--
Mobile Homes Specialist
254 968-8328





John W. Krahn

2005-08-29, 7:55 am

Brent Clark wrote:
> Hi list


Hello,

> I have im trying to enhance my regex skill.
>
> My questions is, would
>
> m/^p11[016]/io
>
> match like
>
> m/^(p110|p111|p116)/io
>
> Any tips or advice, would greatfully be appreciated.


It appears that they would both match the same string although I would think
that the second example would be slower and less efficient as using
alternation as well as capturing parentheses is usually slower. If in doubt,
use the Benchmark module to test your assumptions.



John
--
use Perl;
program
fulfillment
Sponsored Links







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

Copyright 2008 codecomments.com