Replace and add at end of the line

Viewed 50

I need to replace some starting text with another one and add at the end another text. This is a starting example:

- This is a phrase that match
Another - Phrase
Yes another - one
- This also match

The result i want to have is:

$This is a phrase that match%
Another - Phrase
Yes another - one
$This also match%

So replace "- " with "$" (only if is the first two character of the sentence) and add at the end of the line, if match, "%"

I have search and the the replace function work but i don't know how to add the end of line:

With Selection.Find 
 .ClearFormatting 
 .Text = "- " 
 .Replacement.Text = "$" 
 .Execute Replace:=wdReplaceAll, Forward:=True, Wrap:=wdFindContinue 
End With

I have see there is a InsetAfter method but it create a new line, or i have wrong implemented. Suggestions? Thanks

1 Answers

You don't even need a macro for this! All you need is a wildcard Find/Replace, where:

Find = ^13- ([!^13]@)^13
Replace = ^p$\1%^p
Related