RegEx Replace Text -- strip leading and trailing spaces

Matt Denton matt.denton at limelight.com.au
Wed Apr 13 06:14:34 EDT 2005


G'day all

Regular Expression syntax in ReplaceText is driving me a bit loopy 
right now, I was hoping someone out there could work out what I'm doing 
wrong...

I want a single RegEx expression using ReplaceText to strip out leading 
and tailing spaces, leaving any spaces in the middle untouched.

I've got it working in 2 lines of code, but I'm SURE I can do it in 
one.  (I've spent an hour trying to reduce this to one line... I know, 
why not go for a swim or something more constructive with my time...)

This works:

put replaceText(tSomeText, "^ +",empty) into tFirstPass
put replaceText(tFirstPass, " +$",empty) into tSecondPass

But when I try and combine:

put replaceText(tSomeText, "^ ?| +$",empty) into tOnePass

I can't get it to work!!  I've tried many variations and the logic 
SEEMS to be right... obviously not.

Anyone?  I'll award the winner with a jar of Vegemite from Australia.

Cheers

M@
Matt Denton



More information about the use-livecode mailing list