1
Si cum îi semănau ! Fraţi buni, puindu-si, ca si el, tot sufletul 
în ceea ce făceau, muncind din greu, luptind din greu, jert- 
findu-se, fără nici un gînd de răsplată.

Simțind în tot ceasul, 
asupra destinului lor, o poruncă ce vine mai de departe Si 
poruncește mai straşnic decît cea pe care le-o strigă împre- 
jurarile. În fata îngrozitoarei tragedii a războiului, un pictor 
nou se destepta în Grigorescu.

Must Become:

Şi cum îi semănau ! Fraţi buni, puindu-si, ca si el, tot sufletul în ceea ce făceau, muncind din greu, luptind din greu, jertfindu-se, fără nici un gînd de răsplată.

Simțind în tot ceasul, asupra destinului lor, o poruncă ce vine mai de departe Si poruncește mai straşnic decît cea pe care le-o strigă împrejurarile. În fata îngrozitoarei tragedii a războiului, un pictor nou se destepta în Grigorescu.

For this, right now I am using 2 regex formulas:

FIND: -\s+

REPLACE BY: (leave empty)

and

FIND: \n\s+

REPLACE BY: (leave empty)

Especially, be careful that the end of some lines have something like this: "jert- findu-se", this means that the word is divided in two. This kind of words must be connected, but without a hyphen, like this: "jertfindu-se"

How can I combine the two regex formulas into one, so as to obtain the same result?

I tried such a combination, but it's not very good:

FIND: (-\s+)|\1|(?=(\n\s+))|\2

OR

FIND: [\n-](\s+)|(\s+)|\1|\2

2
  • as regex try something like: [\n-]\s+ Commented Jul 25, 2023 at 9:57
  • nope, the same as my solution with combination. So, your regex, as mine, do not put the second sentence on the same line.
    – Just Me
    Commented Jul 25, 2023 at 9:59

1 Answer 1

1
  • Ctrl+H
  • Find what: (?<!\n)(?:-\h*)?\R(?!\R)
  • Replace with: LEAVE EMPTY
  • TICK Wrap around
  • SELECT Regular expression
  • Replace all

Explanation:

(?<!\n)     # negative lookbehind, make sure we haven't a linebreak before
(?:         # non capture group
    -           # hyphen
    \h*         # 0 or more horizontal spaces
)?          # end group, optional
\R          # any kind of linebreak
(?!\R)      # negative lookahead, make sure we haven't linebreak after

Screenshot (before):

enter image description here

Screenshot (after):

enter image description here

6
  • super answer, thanks @Toto
    – Just Me
    Commented Jul 25, 2023 at 10:12
  • your regex is almost good, but not perfect. After FIND/REPLACE some words become linked, instead of being separated by space. For example: Si poruncește become after Replace Siporuncește
    – Just Me
    Commented Jul 25, 2023 at 10:23
  • @JustMe: See my edit.
    – Toto
    Commented Jul 25, 2023 at 10:39
  • almost good :) But pe care le-o strigă împre- jurarile becomes pe care leo strigă împre jurarile. Should be: pe care le-o strigă împrejurarile. So you have to delete the dash from the end of the line (where it is) and connect the words that it separates. Then, you must delete only the dash at the end of the lines, not the other dashes included in the line.
    – Just Me
    Commented Jul 25, 2023 at 11:07
  • 1
    @JustMe: It should be good now. The difficulty comes from the space at the end of the lines.
    – Toto
    Commented Jul 25, 2023 at 11:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .