12

Geany, like many text editors, has a replace dialog:

Geany replace

In the Replace with: field, how can I express that I want the pattern to get replaced with a new line character?

Peter Mortensen
  • 12,090
  • 23
  • 70
  • 90
Nicolas Raoul
  • 10,711
  • 18
  • 64
  • 102

2 Answers2

21

How can I express that I want the pattern to get replaced with a new line character?

  • Set "Replace with" to \n
  • Enable "Use regular expressions"
  • Enable "Use multi-line matching"

Regular expression syntax

enter image description here

Source Regular expression syntax

Peter Mortensen
  • 12,090
  • 23
  • 70
  • 90
DavidPostill
  • 153,128
  • 77
  • 353
  • 394
  • 1
    Note: if you have literal "\n" strings in a file and need them replaced with newlines, first do a non-regex replace of "\n" with something like "ThisIsANewLine", and then do the regex replace of "ThisIsANewLine" with "\n" – SteveDonie Oct 13 '15 at 14:47
  • 3
    @SteveDonie If you have a literal "\\n" to replace it is easier to just escape the "\" using "\\n" – DavidPostill Oct 13 '15 at 14:51
1

The selected answer did not work for me. What did work was checking 'Use escape sequences,' then using the '\n' in the replace field.

This was using Geany 0.21 which did not have "Use multi-line matching."

After updating Geany to 1.30.1 which does have "Use multi-line matching" the selected answer should work.

jacknad
  • 181
  • 1
  • 4
  • What version and platform? Both methods worked for me (Geany 1.36 (2020-03-22) on [Ubuntu MATE 20.04](https://en.wikipedia.org/wiki/Ubuntu_MATE#Releases) (Focal Fossa) base with [Cinnamon](https://en.wikipedia.org/wiki/Cinnamon_(desktop_environment))). – Peter Mortensen Jun 29 '20 at 19:53
  • Can you [add it](https://superuser.com/posts/1558182/edit) to the answer (***without*** "Edit:", "Update:", or similar)? – Peter Mortensen Jun 29 '20 at 21:42