Applescript "Replace" example from the extended text suite


#1

Does anyone have an example of using the “replace” command in an applescript?

From the definition in the applescript dictionary I can’t figure out what the proper syntax would be, and I can’t find an example of the command being used anywhere. The definition posted is:

replace
replace (verb) (from Extended Text Suite)
COMMAND SYNTAX
replace rich text ¬
matching regular expression text ¬
replacement text ¬
string text
PARAMETERS
Parameter
Required
Type
Description
direct parameter required rich text
matching regular expression optional text Regular expression to find
replacement required text Replacement string
string optional text String to find
CLASSES
The following classes respond to the replace command:
cell character word attachment
rich text paragraph attribute run file attachment


#2

It took a while with a LOT of experimenting but I finally got it to work!!!
Here are two examples using regular expressions:

set grepString2 to "
CSN:
" & “\” & “d” & “+”
set grepString4 to “Sex: \n”
set newText to replace (topic of item 1 of selected row of front document) matching regular expression grepString4 replacement "Sex: "
set newText to replace (topic of item 1 of selected row of front document) matching regular expression grepString4 replacement “”