Way to do RegEx substring replacements?

Jim Ault JimAultWins at yahoo.com
Sun Mar 5 01:09:29 EST 2006


On 3/4/06 6:40 PM, "Jim Witte" <jswitte at bloomington.in.us> wrote:

> Is there a way in Revolution (2.0.3) to do a RegEx find and replace
> using one of the sub-expressions, like finding
> 
> (....) ([^x]*)x.*
> 
> and replacing by
> 
> \1\t\2
> 
> directly without having to use matchText to extract the
> subexpressions and then construct the line?
Not that I know of, but I am curious why this is needed.

Be careful that you only have one possible match and that you consider
'greedy' and case sensitive when applying RegEx since \1  and \2 may not be
what you expect.

If given that there is only one possible way to get a match then it is not
really a problem to use two lines to produce the result:

put matchText(lineOfText, "(?Ui)(...)([^x]*)x.*",v1,v2) into vTrueFalse
if vTrueFalse = "true" then
   put v1 & tab & v2 into outputStr
else
   answer "Match not successful, take alternate actions"
end if

Why is this an issue for you?
Do you mean that you want to do more than one replacement in a single text
block?  In that case, I use matchChunk & a repeat loop & temp variables.

>(Yes, I know this should
> be in Perl, Python, or something else - that's next after the
> prototype is done)
Not sure what you mean by this.  I use RegEx quite often in Rev routines, as
well as filter, replace, replaceText.

Jim Ault
Las Vegas





More information about the Use-livecode mailing list