Find/replace in each paragraph of the selection
Posted: 2019-09-08 13:58:03
A document of mine contains some text like the following (there's a tab between the text and the number; apparently forum sw doesn't allow it):
Some text 12
Other text 43
Some more text 62
etc
I would like to select all that lines and run a macro that adds a prefix and suffix to each line—two fixed strings:
Pre Some text 12 Post
Pre Other text 43 Post
Pre Some more text 62 Post
etc
That's what I cobbled together so far:
The macro seems to loop through the lines and find/replace lines' text but I don't know how to actually modify the text in the document.
Any help with this trivial problem would be greatly appreciated!
Some text 12
Other text 43
Some more text 62
etc
I would like to select all that lines and run a macro that adds a prefix and suffix to each line—two fixed strings:
Pre Some text 12 Post
Pre Other text 43 Post
Pre Some more text 62 Post
etc
That's what I cobbled together so far:
Code: Select all
$doc = Document.active
if $doc == undefined
exit # exit silently
end
$selection = $doc.selection
$lines = $selection.subtext.find '^.+\n','Ea'
foreach $line in $lines
$myNewLine = $line.subtext.findAndReplace '^.+?\t\d+', 'Pre ' & '\0' & ' Post', 'E'
$selection.subtext.replaceInRange $line.range, $myNewLine
End
Any help with this trivial problem would be greatly appreciated!