Compare numeric strings with leading zeros

Lyn Teyla lyn.teyla at
Fri Sep 4 01:40:21 EDT 2015

Thierry Douez wrote:

> put  "\Q^5$\E"  into  myVeryStrongPassword
> if matchText( userTyping,  myVeryStrongPassword ) then ...

Here is indeed an example of the danger involved with the use of regular expressions.

It can be easy to miss things at times, which is why I simply cautioned against using it, rather than completely advise against it.

There are many ways to skin a cat, so yes, whilst it *is* possible to utilize Regex to perform certain tasks if done correctly, it's also easy to make mistakes (hence the caution) even for those who are comfortable with Regex.

> Ok, now I'm waiting for what I've missed...

Your revised example was missing a "^" at the beginning and a "$" at the end.

   put "^\Q^5$\E$" into myVeryStrongPassword

Here is an example showing the issue:


on mouseUp
   local userTyping = "00^5$6"
   local myVeryStrongPassword = "^5$"
   put stringsAreEqual(userTyping, myVeryStrongPassword) & cr into msg
   put stringsAreEqual.err(userTyping, myVeryStrongPassword) & cr after msg
end mouseUp

function stringsAreEqual pString1, pString2
   return matchText(pString1, "^\Q" & pString2 & "\E$")
end stringsAreEqual

function stringsAreEqual.err pString1, pString2
   return matchText(pString1, "\Q" & pString2 & "\E")
end stringsAreEqual.err


Hope this clarifies things.


More information about the use-livecode mailing list