Regular expression replace
peter lemay
plemay at readnaturally.com
Fri Sep 9 11:49:15 EDT 2005
Hi.
I want to do several replaces using a regular expression in Revolution.
Here are two runable examples, but they both have problems.
In these examples, I want these replacements:
[rnNF2] replaced by [2F]
[rnNF3] replaced by [3F]
[rnNW3] replaced by [3W]
The first example uses replaceText and works as a 'replace all'. But the
3rd parameter is a literal. When I try this, the $1 and $2 do not
represent the (parenthesis-delimited) groups the way normal regex does.
The second example uses matchText and only replaces the first instance.
I could probably use this in a repeat, but there should be a better way.
Any suggestions?
Pete
***
put "the first test [rnNF2] the second test [rnNF3] and the third test
[rnNW3] are all here" into testIn
answer testIn
put replaceText(testIn, "\[rnN([FWS])([1-8])\]", "[$2$1]") into testOut
answer testOut
***
put matchText(testIn,"\[rnN([FWS])([1-8])\]", theSeason, theGrade) into
gotPhone
answer "gotPhone=" & gotPhone & ", theSeason=" & theSeason & ",
theGrade=" & theGrade
***
More information about the use-livecode
mailing list