RegEx Replace Text -- strip leading and trailing spaces

Ken Ray kray at sonsothunder.com
Wed Apr 13 21:12:22 EDT 2005


On 4/13/05 7:22 PM, "Trevor DeVore" <lists at mangomultimedia.com> wrote:

> On Apr 13, 2005, at 4:49 PM, Ken Ray wrote:
>>   get matchText(pWhat, "(?s)^\s+(.*?)\s+$", tReturnVal)
>> 
>> I agree that the "word 1 to -1" solution will do what you want 95+% of
>> the
>> time, but just wanted to make sure that everyone knew there was at
>> least one
>> 'hole' in that approach in case anyone cared. ;-)
> 
> Ah, good catch Ken.  I think the only thing that needs changing is the
> "+" sign after the \s.  With this version if there is no white space at
> the beginning or end of the string then no result is returned in
> tReturnVal.  So the modified (and hopefully all-encompassing) version
> is:
> 
> get matchText(pWhat, "(?s)^\s*(.*?)\s*$", tReturnVal)

Equally good catch, Trevor... I'll update my library.

:-)

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




More information about the use-livecode mailing list