Home > database >  Merge words with hyphenation and line breaks (regex)
Merge words with hyphenation and line breaks (regex)

Time:12-07

When a hyphenated word is separated by a line break, I want to merge them. So the condition is that a hyphen is followed by a line break. If a hyphen is followed by a whitespace, nothing at all should happen.

This is to be merged because a line break follows:

This is a ice-
cream and this is a car 

And in such examples, nothing at all should be merged because the line is clean.

This is a ice-cream and this is a car

How can I do this with regular expressions (I use Notepad )?

If I use the following regular expression, then everything is just merged.

  • Search for: [^\s-]\K-\s (?=[^\s-]) ()
  • Replace with: nothing

CodePudding user response:

Try -\R(?=[^\s]) and replace by - if you want to keep the dash, otherwise replace it with an empty string.

CodePudding user response:

(?<=-)\n and replace with nothing (enter image description here

  • Related