Perl regexps compared to Python regexps 
Author Message
 Perl regexps compared to Python regexps

Quote:

> Without wishing to start a Perl vs python discussion, I was wondering does
> anyone out there know if there are any major differences between the the two
> languages implementations of regular expressions. Lots of net resources seem
> to imply that Python's implementation is less powerful but with my limited
> use of Python and having looked at the documentation, I cannot really find
> any evidence for this. Have I picked up the wrong end of the stick or am I
> missing something ?

> Many thanks

> Matt Freake

Matt, if you really want a *complete* discussion on this subject, get a
copy of Jeffrey Friedl's book 'Mastering Regular Expressions'.  You'll
learn FMTYEWTK about the differences.  Perl has some regex features that
nobody else has, and Friedl's tests suggest that well-written Perl
regexes
should be much faster [although badly-written Perl regexes can be pain-
fully slow - a potential problem in any NFA regex engine].

But.. both Python and Perl are constantly being improved.  So YMMV.

Of course, since you asked this in a Perl ng, you should expect that
we'll all insist {*filter*}ly that Perl is the best.  :-)

David
--
David Cassell, OAO                              

Senior Computing Specialist                          phone: (541)
754-4468
mathematical statistician                              fax: (541)
754-4716



Fri, 28 Sep 2001 03:00:00 GMT  
 Perl regexps compared to Python regexps
[A complimentary Cc of this posting was sent to David Cassell


Quote:
> > Without wishing to start a Perl vs Python discussion, I was wondering does
> > anyone out there know if there are any major differences between the the two
> > languages implementations of regular expressions. Lots of net resources seem
> > to imply that Python's implementation is less powerful but with my limited
> > use of Python and having looked at the documentation, I cannot really find
> > any evidence for this. Have I picked up the wrong end of the stick or am I
> > missing something ?

> Matt, if you really want a *complete* discussion on this subject, get a
> copy of Jeffrey Friedl's book 'Mastering Regular Expressions'.  You'll
> learn FMTYEWTK about the differences.

No he will not.  Hip Owl is several years old, which makes it
completely useless for this particular question.

Hope this helps,
Ilya



Fri, 28 Sep 2001 03:00:00 GMT  
 Perl regexps compared to Python regexps

Quote:

>... and Friedl's tests suggest that well-written Perl regexes
>should be much faster [although badly-written Perl regexes can be pain-
>fully slow - a potential problem in any NFA regex engine].

I have, until now, never encountered a Perl regex that is "painfully
slow", or not even "rather on the slow side". Can anybody please give an
example of such a beast, point out the reason for it's slowness, and
possibly even recipes on what to avoid?

        Bart.



Fri, 28 Sep 2001 03:00:00 GMT  
 Perl regexps compared to Python regexps

<URL::">
^^
^^ >... and Friedl's tests suggest that well-written Perl regexes
^^ >should be much faster [although badly-written Perl regexes can be pain-
^^ >fully slow - a potential problem in any NFA regex engine].
^^
^^ I have, until now, never encountered a Perl regex that is "painfully
^^ slow", or not even "rather on the slow side". Can anybody please give an
^^ example of such a beast, point out the reason for it's slowness, and
^^ possibly even recipes on what to avoid?

"aaaaaaaaaaaaaaaaaaaaaab"  =~  /a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a.c/;

Abigail
--

0)x299=>C=>(0)x9=>XC=>(0)x39=>L=>(0)x9=>XL=>(0)x29=>X=>IX=>0=>0=>0=>V=>IV=>0=>0
=>I=>$r=-2449231+gm_julian_day+time);do{until($r<$#r){$_.=$r[$#r];$r-=$#r}for(;
!$r[--$#r];){}}while$r;$,="\x20";print+$_=>September=>MCMXCIII=>()'



Fri, 28 Sep 2001 03:00:00 GMT  
 Perl regexps compared to Python regexps

Quote:

>Without wishing to start a Perl vs Python discussion, I was wondering does
>anyone out there know if there are any major differences between the the two
>languages implementations of regular expressions. Lots of net resources seem
>to imply that Python's implementation is less powerful but with my limited
>use of Python and having looked at the documentation, I cannot really find
>any evidence for this. Have I picked up the wrong end of the stick or am I
>missing something ?

I'm not a python expert by any stretch of the imagination so I'm probably
wrong, but I'll blab anyway...

I believe python regular expression are as powerful as older perl
regular expressions. I think python uses perl style regular expressions now,
but not the cutting edge version. This means python misses out on the
newer features that no one knows about anyway? Look-behind is an example
I believe (I could be wrong on this).

To confuse matters python has two regular expression libraries. The older one
is not like perl at all. The newer one is perl style. If the documentation
you are looking at is old or regarding the older style regexes they won't
be perl like at all.

I think th 're' library is the perl like one, and 'regexp' the other one. I
might have it backwards of course.

A python user will know much better than clpm readers...

--
Sam

So I did some research. On the Web, of course. Big mistake...
        --Larry Wall



Sat, 29 Sep 2001 03:00:00 GMT  
 Perl regexps compared to Python regexps

Quote:

> I believe python regular expression are as powerful as older perl
> regular expressions. I think python uses perl style regular expressions now,
> but not the cutting edge version. This means python misses out on the
> newer features that no one knows about anyway? Look-behind is an example
> I believe (I could be wrong on this).

Python's "re" is based on Philip Hazel's PCRE, and is extremely similar
to Perl 5.005's regular expressions.  It's got lookbehind, once-only
subpatterns, and conditional subpatterns, as well as the earlier stuff.
I don't know how they compare in terms of performance, though I'd be
interested in hearing anyone's experience.

--



Sat, 29 Sep 2001 03:00:00 GMT  
 Perl regexps compared to Python regexps

Quote:

> ^^ I have, until now, never encountered a Perl regex that is "painfully
> ^^ slow", or not even "rather on the slow side". Can anybody please give an
> ^^ example of such a beast, point out the reason for it's slowness, and
> ^^ possibly even recipes on what to avoid?

> "aaaaaaaaaaaaaaaaaaaaaab"  =~  /a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a.c/;

*OUCH*! that hurts...

I'd read about this, but never really played around to see just how bad it
can get...

"aaaaaaaaaaaaaaaab"  =~  /a*a*a*a*a*a*a*a*a*a*a*a*a*a.c/;

took 115 seconds, up from 29 seconds with only 1 less a/a* in it

(I left the original one going for an hour before I gave up on it...)

Iain



Sat, 29 Sep 2001 03:00:00 GMT  
 Perl regexps compared to Python regexps
[A complimentary Cc of this posting was sent to Lindsey


Quote:


> > I believe python regular expression are as powerful as older perl
> > regular expressions. I think python uses perl style regular expressions now,
> > but not the cutting edge version. This means python misses out on the
> > newer features that no one knows about anyway? Look-behind is an example
> > I believe (I could be wrong on this).

> Python's "re" is based on Philip Hazel's PCRE, and is extremely similar
> to Perl 5.005's regular expressions.  It's got lookbehind, once-only
> subpatterns, and conditional subpatterns, as well as the earlier stuff.
> I don't know how they compare in terms of performance, though I'd be
> interested in hearing anyone's experience.

Note that Python does not allow executable code in RExen, but Perl has
no named subpatterns.  And 5.005_5* has infinitely more powerful (but
not completely ironed out yet) 'embedded' patterns.

Moreover, Perl REx-repetitors are stack-based (at least the
"complicated" ones), which may lead to problems with a short stack.
Do not know about Python's ones.

Ilya



Sat, 29 Sep 2001 03:00:00 GMT  
 Perl regexps compared to Python regexps

Quote:

> Without wishing to start a Perl vs Python discussion, I was wondering
> does anyone out there know if there are any major differences between
> the the two languages implementations of regular expressions.

The overall answer is that unless you're doing fairly odd and special
things and deeply grok and appreciate the stuff that Ilya's put into the
latest and greatest Perl regex engines, you'll never notice the difference
except for syntax.

Perl's engine is arguably more powerful, but the added power is all in
fairly obscure areas.

--
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker





Sat, 29 Sep 2001 03:00:00 GMT  
 
 [ 26 post ]  Go to page: [1] [2]

 Relevant Pages 

1. regexps with index(), regexps vs strings, clarify $*

2. Taint and regexps [was: How to start your Perl CGI script]

3. embedded perl: regexps

4. Need help with perl regexps

5. Perl bug (segmentation fault with require and lots of regexps)

6. Formale Beschreibung von (Perl) RegExps

7. Newbie needs help with perl regexps

8. Newbie needs help with perl regexps

9. Newbie needs help with perl regexps

10. Self-referential regexps in Perl/ Representation of C++ templates as a regexp

11. Perl 5 regexps as independant package?

12. Perl vs C regexps

 

 
Powered by phpBB® Forum Software