RegEx Replace Text -- strip leading and trailing spaces

Trevor DeVore lists at mangomultimedia.com
Wed Apr 13 20:22:59 EDT 2005


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)

Of course this may be missing something obvious too given my track 
record today.  Maybe it is time for a vacation...


-- 
Trevor DeVore
Blue Mango Multimedia
trevor at mangomultimedia.com



More information about the use-livecode mailing list