[Tutor] Amazing power of Regular Expressions...

Asrarahmed Kadri ajkadri at googlemail.com
Sat Nov 4 16:46:22 CET 2006


Hi Folks,


I dont know much about Regular Expressions. But I just want to share my
ideas.

I was trying to implement error checking code on the date argument:

I did this:

import re
# the user should enter date in the format: dd/mm/yyyy
p = re.compile('\d\d/\d\d/\d\d\d\d')

m = p.match(date)

the function match will return an object of type SRE_Match only if the user
has supplied the string in the form of dd/mm/yyyy. If the user tries to
supply negative values, then match will return None.
So no hassle of using all those Ifs  and Elifs........
I think REGULAR Expressions can be quite powerful...

Regards,
Asrarahmed
-- 
To HIM you shall return.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20061104/3c022b56/attachment.html 


More information about the Tutor mailing list