AW: AW: How trim: Bug in RegExp engine
fischer at mail.sub.uni-goettingen.de
Tue Oct 25 17:39:22 EDT 2005
Hi Dave and all the others in this thread,
> ... I guess the engine is confused about where the replacement
> should be made. As far as I know, replaceText always works when the
> above construction is used in combination with another expression
> (e.g yx*, x*y, yx*z), so if it is a bug, I don't think it can be
> considered a serious one.
> >> answer replaceText("A C","^ +","")
> The above works because the match can fail, in which case no
> replacement is made.
1. You're absolutely right, I should have used "^ +" in the first place.
2. I didn't want to sound too harsh, sorry. I called this a serious bug, because for somebody who has some Perl programming experience, regular expression lie at the very basis of the script, so I was somewhat shocked. And in spite of what Ken Ray says, I still think this is a bug.
3. It seems that regular expressions are to be avoided in time sensitive parts of the script anyway. Playing around a little bit I found that the RegExp solution I suggested took far more time than any other solution (by about a factor of 10 compared with the fastest solution). Probably this should be optimized in an updated version. It seems that regular expressions in Perl are by a factor 6 faster (and again 8 times faster on my PC laptop).
On the other hand, this shows that those cumbersome repeat loops are surprisingly fast.
The fastest is:
while char 1 of testString is space
delete char 1 of testString
taking about 1.8 microseconds per round (11 ticks for 100000 repeats), and with a string whiteSpace = tab && return a loop with
while char 1 of testString is in whiteSpace
takes about twice as long.
word 1 to -1 of testString
removing whitespace at the front and the end simultaneously is only a little slower, while using token
token 1 to -1 of testString
takes surprisingly three times as long as using "word".
All in all, Bob's idea "to ask questions that make them want to crawl under the table in shame because probably the answer is idiotically simple." turned out to keep people busy and excited for quite a while. Proves again that there are no simple questions...
All the best
Salzburg (actually Gottingen right now)
More information about the Use-livecode