Selecting text using REGEX

Ken Ray kray at sonsothunder.com
Fri Oct 17 13:11:08 EDT 2003


> > function Trim what
> >   local tText
> >   get matchText(what,"(?s)\s*(\S.*\S)\s*",tText)
> >   return tText
> > end Trim
> 
> Beware this function fails for 
> single-character-with-whitespace strings 
> like " s" and " 9 ". By changing the regex to 
> "(?s)\s*(\S.*\S?)\s*" and 
> checking the result of matchText(), we can make it safer. But 
> it still 
> was failing some of my tests- I can't remember which strings though.

Thanks for the heads-up, Alex. I'll see if there's a better way to do it
and repost to the list when I have it...

Ken Ray
Sons of Thunder Software
Email: kray at sonsothunder.com
Web Site: http://www.sonsothunder.com/ 




More information about the use-livecode mailing list