AW: How trim: Bug in RegExp engine
Thomas Fischer
fischer at mail.sub.uni-goettingen.de
Sun Oct 23 06:03:47 EDT 2005
Hi,
Wouter is right:
> It is indeed elegant, but a condition check is necessary here as it
> will remove the first word + the space(s) if there is no space at the
> start of the line.
>
> > " The cat sat on the mat. "
> But if no space in front the result is
>
> "cat sat on the mat. "
>
This is actually true -- and a serious bug in Revolution's RegExp engine.
The Regular Expression Syntax reference states:
^ matches the following character at the beginning of the string
^A matches "ABC" but not "CAB"
* matches zero or more occurrences of the preceding character or pattern
I assumed that Revolution would do what it promised and didn't check this.
Try
answer replaceText("A C","^ *","")
I get "C", which obviously is not correct.
If I remove the "*", I get "A C"
And
answer replaceText("BAC","^A*","")
gives "C", so "^A*" matches "BA".
This must not happen.
It looks like "^A*" is incorrectly interpreted as "^.*A*".
Parentheses don't help, but might make things worse:
answer replaceText("BAC","(^A)*","")
gives an empty result. No idea why.
All the best
Thomas
--
Thomas Fischer
Salzburg
More information about the use-livecode
mailing list