huypham99
huypham99

Reputation: 67

How to replace text and add a other specific text at the end of that line in notepad++

I have a file containing below text for example:

the brown fox
the red fox
the brown cat

I want to replace "brown" with "yellow" and add "edited" at the end of line so that content of the file would be:

the yellow fox edited
the red fox
the yellow cat edited

Please tell me the solution!

Thanks for your help.

Upvotes: 1

Views: 1419

Answers (2)

Toto
Toto

Reputation: 91518

  • Ctrl+H
  • Find what: \bbrown\b(.+)$
  • Replace with: yellow$1 edited
  • CHECK Wrap around
  • CHECK Regular expression
  • UNCHECK . matches newline
  • Replace all

Explanation:

\bbrown\b       # literally brown surround with word boundaries to avoid matching "brownies" or "whateverbrown"
(.+)            # group 1, 1 or more any character but newline
$               # end of line

Replacement:

yellow          # literally
$1              # content of group 1 (every thing after brown) followed by a space
edited          # literally

Screen capture (before):

enter image description here

Screen capture (after):

enter image description here

Upvotes: 3

vs97
vs97

Reputation: 5859

This will need to be done in two steps:

Ctrl + H

First step: using regex (make sure "Regular expression" is toggled in Search Mode below), find if sentence contains brown and append edited to end of sentence:

enter image description here

the brown fox edited
the red fox
the brown cat edited

Second step is easy - replace brown with yellow.

the yellow fox edited
the red fox
the yellow cat edited

Upvotes: 2

Related Questions