builtin regular expressions?
steve at holdenweb.com
Sat Sep 30 18:46:03 CEST 2006
Mirco Wahab wrote:
> Thus spoke Antoine De Groote (on 2006-09-30 11:24):
>>Can anybody tell me the reason(s) why regular expressions are not built
>>into Python like it is the case with Ruby and I believe Perl? Like for
>>example in the following Ruby code
>>I'm sure there are good reasons, but I just don't see them.
>>Python Culture says: 'Explicit is better than implicit'. May it be
>>related to this?
> I think it is exactly because the /\b(\d+)\s+\/\//
> together with $_ and $whatever=~/\/\/(?=\d+)/ are
> seen as the 'line noise' everybody talks about ;-)
> Regex as part of the core language expressions
> makes code very very hard to understand for
> newcomers, and because Python is ...
> To invoke an additional cost in using Regexes,
> the language simply prevents them in a lot of
> situations. Thats it. You have to think three
> times before you use them once. In the end,
> you solve the problem 'elsewise' because of
> the pain invoked ;-)
Tim Peters frequently says something along the lines of "If you have a
problem and you try to solve it with regexes, then you have TWO
problems". This isn't because the Python use of regexes is more
difficult than Perl's: it's because regexes themselves are inherently
difficult when the patterns get at all sophisticated.
If you think Perl gives better text-handing features nobody is going to
mind if you use Perl - appropriate choice of language is a sign of
maturity. Personally I tend to favour the way Python does it, but I
don't require that anyone else does.
The real answer to "why doesn't Python do it like Perl?" is "Because
Python's not like Perl".
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden
More information about the Python-list