AndrewMk
AndrewMk

Reputation: 703

Notepad++ Replacing Text Between Two Strings Using Regular Expression

Got something like this

<[email protected]>[email protected]

<[email protected]>[email protected]

I want to select all the text that is between every <> in the whole script and replace it with a definite value. I also want to leave out all the text that is not in between <> unaffected.

Tried using this expression <.*> but then the whole script got selected, including the text that is not between <>

Upvotes: 5

Views: 24651

Answers (1)

Toto
Toto

Reputation: 91385

  • Ctrl+H
  • Find what: (?<=<).+?(?=>)
  • Replace with: New_value
  • check Wrap around
  • check Regular expression
  • UNCHECK . matches newline
  • Replace all

Explanation:

(?<=<)      # positive lookbehind, make sure we have "<" before
.+?         # 1 or more any character but newline
(?=>)       # positive lookahead, make sure we have ">" after

Screen capture:

enter image description here

Further reading

Upvotes: 9

Related Questions