Re: [Tutor] Amazing power of Regular Expressions...

2006-11-06 Thread Jonathon Sisson
John, Thanks...I was a bit deep in a script trying to figure out why I kept getting global key errors (trying to make sure that re.compile and import re weren't run but once...doh?) when you responded. I guess that settles it, then...for this particular instance, '"J" in s' is indeed faster th

Re: [Tutor] Amazing power of Regular Expressions...

2006-11-06 Thread John Fouhy
On 07/11/06, Jonathon Sisson <[EMAIL PROTECTED]> wrote: > Just out of curiousity (since I really can't say myself), does the code > below import re each time it loops? I ran the same commands and saw > quite similar results (0.176 usec per loop for the first test and 0.993 > usec per loop for the

Re: [Tutor] Amazing power of Regular Expressions...

2006-11-06 Thread Jonathon Sisson
Just out of curiousity (since I really can't say myself), does the code below import re each time it loops? I ran the same commands and saw quite similar results (0.176 usec per loop for the first test and 0.993 usec per loop for the second test), and I was just curious if that import (and the

Re: [Tutor] Amazing power of Regular Expressions...

2006-11-06 Thread John Fouhy
On 07/11/06, Kent Johnson <[EMAIL PROTECTED]> wrote: > If anyone really cares which Python implementation is faster, the timeit > module is your friend. Assertions like "would probably be faster" or > "it's also quicker" don't hold much weight. In Python, if you want to > know what is faster, you m

Re: [Tutor] Amazing power of Regular Expressions...

2006-11-06 Thread Alan Gauld
"Michael Sparks" <[EMAIL PROTECTED]> wrote > A regex compiles to a jump table, and executes as a statemachine. Sometimes, but it depends on the implementation. If someone uses a C++ compiler that uses the standard library implememation of regex (like say the Microsoft Visual C++ version up till V

Re: [Tutor] Amazing power of Regular Expressions...

2006-11-06 Thread Kent Johnson
Alan Gauld wrote: > "Michael Sparks" <[EMAIL PROTECTED]> wrote >> >> That's equivalent to the regular expression: >>* ^[0-9A-Za-z_.-]*$ > > While using a dictionary is probably overkill, so is a regex. > A simple string holding all characters and an 'in' test would probably > be both easier to

Re: [Tutor] Amazing power of Regular Expressions...

2006-11-06 Thread Michael Sparks
On Monday 06 November 2006 01:08, Alan Gauld wrote: > While using a dictionary is probably overkill, so is a regex. No, in this case it's absolutely the right choice. > A simple string holding all characters and an 'in' test would probably > be both easier to read and faster. I'm stunned you th

Re: [Tutor] Amazing power of Regular Expressions...

2006-11-05 Thread Alan Gauld
"Michael Sparks" <[EMAIL PROTECTED]> wrote > The most pathological example of regex avoidance I've seen in a > while > is this: > > def isPlain(text): >plaindict = {'-': True, '.': True, '1': True, '0': True, '3': > True, > '2': True, '5': True, '4': True, '7': True, '6': True, '9': >

Re: [Tutor] Amazing power of Regular Expressions...

2006-11-05 Thread Kent Johnson
Michael Sparks wrote: > On Sunday 05 November 2006 15:02, Kent Johnson wrote: > ... >> Regular expressions are an extremely powerful and useful tool that every >> programmer should master and then put away and not use when there is an >> alternative :-) > > > > There's always an alternative to a

Re: [Tutor] Amazing power of Regular Expressions...

2006-11-05 Thread Michael Sparks
On Sunday 05 November 2006 15:02, Kent Johnson wrote: ... > Regular expressions are an extremely powerful and useful tool that every > programmer should master and then put away and not use when there is an > alternative :-) There's always an alternative to a regular expression, so are you reall

Re: [Tutor] Amazing power of Regular Expressions...

2006-11-05 Thread Kent Johnson
Alan Gauld wrote: > But I sure agree with it. The problem with Regex is that they can > be just a bit too powerful. To cite another programming proverb, > this time by Bjarne Stroustrup I think: > > "C makes it easy to shoot yourself in the foot; > C++ makes it harder, but when you do, > it blows

Re: [Tutor] Amazing power of Regular Expressions...

2006-11-04 Thread Jonathon Sisson
Ahh, sorry, sorry. I haven't been able to locate the thread that I read that summarized passage from, so I can't say who exactly said all of that... Nice quote on C/C++...made me laugh. Jonathon Alan Gauld wrote: > "Jonathon Sisson" <[EMAIL PROTECTED]> wrote > >> of them they're addicting...

Re: [Tutor] Amazing power of Regular Expressions...

2006-11-04 Thread Alan Gauld
"Jonathon Sisson" <[EMAIL PROTECTED]> wrote > of them they're addicting... As Alan Gauld stated in another thread > (I'm > pretty sure it was Alan): You'll get to the point that you want to > use > (regular expressions) all the time, even if they aren't the right > tool Nope, it wasn't me, may

Re: [Tutor] Amazing power of Regular Expressions...

2006-11-04 Thread Jonathon Sisson
Asrarahmed Kadri wrote: > 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... Indeed...Regular expressions were discovered etched into the blade of a sword that had been pl

[Tutor] Amazing power of Regular Expressions...

2006-11-04 Thread Asrarahmed Kadri
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/ p = re.compile('\d\d/\d\d/\d\d\d\d')   m = p.match(da