builtin regular expressions?

Mirco Wahab wahab at chemie.uni-halle.de
Sat Sep 30 12:05:08 EDT 2006


Thus spoke Jorge Godoy (on 2006-09-30 17:50):
> Mirco Wahab <wahab at chemie.uni-halle.de> writes:
> 
> I could make it shorter in Python as well.  But for a newbie that haven't seen
> the docs for strings in Python I thought the terse version would be more
> interesting. 

OK

> At least he'll see that there are methods to do what he wants already builtin
> with the language.

OK

>> sub print_message {
>>    if   (/^(track=)/ ){ print 'Your track is '   .substr($_, length $1)."\n" }
...
> If I were writing in Perl I'd not use substr like this and would write code
> similar to the one the OP posted (i.e., /^track=(.*)/).

Right, I actually tried to match your example as close as I could
get and to use only *simple* Regexes (as stated below). What one
really would do (as you probably meant above) is sth. like:

  sub print_message {
     if   (/^track="(.+?)"/ ){ print "Your track is $1\n" }
     ...

which has a "more complicated" regex that is usually
not understood easily by newbies.

>> OK, I do Perl and Python side by side and didn't reach
>> that point so far, maybe beause I read the Friedel-Book
>>  ( http://www.oreilly.com/catalog/regex2/reviews.html )
>> sometimes and actually *like* the concept of regular expressions.
> 
> I like them as well.  I just don't see the need to use them everywhere. :-) 

I like Python for its radically plain look, my
underlying feeling of Python is: "Pascal", whereas
Perl feels and tastes like "C" to me ;-)

Regards

Mirco



More information about the Python-list mailing list