0

i would want to replace only the first occurence of a specific character /sybmol in a line to be replaced with a particular symbol.

can anybody suggest how could this be achieved

ex : i want to replace first occurence of & with and

input : me & she is playing & she came up with a bat & ball & ballon Output : me and she

susin
  • 1
  • 1
  • Possible duplicate of [REGEX in Notepad++ find/replace](https://stackoverflow.com/questions/37171292/regex-in-notepad-find-replace) – Kobi Apr 26 '18 at 12:51
  • Do you want to remove everything after "she"? – Toto Apr 26 '18 at 13:19
  • nope i just want to replace only the first occurence of a particular word or symbol in a line – susin Apr 27 '18 at 07:32

1 Answers1

1

Do a regular expression find/replace like this:

  • Open Replace Dialog
  • Find What: ^([^&]*)&
  • Replace With: \1and
  • Check regular expression
  • Click Replace or Replace All

Explanation:

  • [^&]* matches everything that is not a & and the first ^ anchors the match at the line start
  • the last part & matches the & and because the first part cannot contain a &, it is the first & in a matched line
  • the parentheses mark the first part for reuse in the replacement as \1
  • so \1 becomes me in your example and the & is replaced by and
Lars Fischer
  • 9,135
  • 3
  • 26
  • 35