I have a large block of text, containing one or more instances of each of a list of words. I need to add a prefix to all instances of each word on the list.
Here's an example of what I'm trying to do -
List of words:
foo
bar
Prefix:
xyz
Text before:
onklnagknaubosabdof foo dklfn fknk foo klnksdnia bar dsknska foo knkn bar
Text after:
onklnagknaubosabdof xyzfoo dklfn fknk xyzfoo klnksdnia xyzbar dsknska xyzfoo knkn xyzbar
How can I do this in Notepad++? Or is there another tool that can do this for me easily?
(?=\b(?:foo|bar)\b)
xyz
Explanation:
(?= # start lookahead, make sure we have after:
\b # word boundary, to NOT match xyzfoo or foobar
(?: # start non capture group
foo # literally
| # OR
bar # literally
) # end group
\b # word boundary, to NOT match xyzfoo or foobar
) #end lookahead
Result for given example:
onklnagknaubosabdof xyzfoo dklfn fknk xyzfoo klnksdnia xyzbar dsknska xyzfoo knkn xyzbar
Screen capture:
If you want to replace foobar
with xyzfooxyzbar
, remove the word boundaries:
(?=(?:foo|bar))