Hello Morley Chalmers,
In addition to concise regular expressions, you may try something like the following code written in plain AppleScript. It will find text blocks defined by given starting tag (=x) and ending tag (=y) and replace each of them with given string (=z).
(Please copy code from this web page, not from subscribed email text.)
Hope this may help,
H
PS.
Satimage-software's site has brief tutorial on regular expression:
http://www.satimage.fr/software/en/downloads/downloadscompanionosaxen.html
http://www.satimage.fr/software/en/smile/text/index.html
If I'm not mistaken, however, 'find' and 'change' commands in Satimage.osax neither support Unicode text nor 'lazy' matching. You'd need Smile (free regular edition or paid full edition) for 'ufind' and 'uchange' commands, which support Unicode text and 'lazy' matching.
--SCRIPT
set t to "1 (tag1)some text(/tag1) 2 (tag1)other text(/tag1) 3"
--set t to "(tag1)text in outer block and (tag1)text in inner block(/tag1)(/tag1)"
return replaceBlocks({"(tag1)", "(/tag1)"}, "REPLACED", t)
on replaceBlocks({x, y}, z, t)
(*
string x, y : block start tag, block end tag
string z : replacing string for each block "x..y"
string t : source text
return string : replaced string -- [1]
[1] This handler does not support nested blocks.
(Only the inner most block will be replaced if nested.)
*)
script o
property tt : {}
property uu : {}
property rr : {}
property astid : a reference to AppleScript's text item delimiters
try
set astid0 to astid's contents
set astid's contents to {x}
set tt to t's text items
set end of my rr to my tt's item 1
set astid's contents to {y}
repeat with i from 2 to count my tt
set uu to my tt's item i's text items
if (count my uu) = 1 then -- y not found after x in this segment
set end of my rr to x & my tt's item i
else
set end of my rr to z & my uu's rest
end if
end repeat
set astid's contents to astid0
on error errs number errn
set astid's contents to astid0
error "replaceBlocks(): " & errs number errn
end try
return my rr's item 1 & my rr's rest
end script
tell o to run
end replaceBlocks
--END OF SCRIPT