Selecting text using REGEX

Alex Rice alex at mindlube.com
Tue Sep 30 23:57:01 EDT 2003


On Sunday, September 28, 2003, at 06:48  PM, Ken Ray wrote:
>
> Interesting... my regEx version of Trim was this:
>
> function Trim what
>   local tText
>   get matchText(what,"(?s)\s*(\S.*\S)\s*",tText)
>   return tText
> end Trim

Thanks Ken this is a good one.

People might be confused about the (?s) since it's not in the 
transcript docs- but it is in the PCRE docs. (?s) says the dot 
metacharacter  matches any character, including newlines. So for 
example:

put space & linefeed & "hello" & linefeed & tab & "world" & tab & space 
into t
put "|" & trim(t) & "|"
-- result is
|hello
	world|


Alex Rice <alex at mindlube.com> | Mindlube Software | http://mindlube.com

what a waste of thumbs that are opposable
to make machines that are disposable  -Ani DiFranco




More information about the use-livecode mailing list