I'm searching for a regex for Notepad to have a text with maximum 35 characters per line.
I want to start a new line:
- at the last whitespace occurrence before the 35th character
- at the last dot occurrence before the 35th character if whitespace is missing
I don't want to start a new line if there aren't any whitespace or dots.
Example text:
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
Excepteur.sint.occaecat.cupidatat.non.proident,.sunt.in.culpa.qui.officia.deserunt.mollit.anim.id.est.laborum.
This regex matches every line until the 35th character but I don't know how to add the whitespace/dot selection:
^.{0,35}
Can you help me?
Thanks
CodePudding user response:
You can use
Find What: ^(?=.{35}).{0,35}[\h.]
Replace With: $0\n
Details:
^
- start of a line(?=.{35})
- a positive lookahead that requires 35 chars other than line break chars to appear immediately to the right of the current location.{0,35}
- zero to 35 chars other than line break chars[\h.]
- either a horizontal whitespace or a dot.
The replacement pattern is the whole match ($0
) plus a line feed char.
See the Notepad demo and settings: