Forum Archive

Problem with Find/Replace regex : \n (newline) and \b (boundary) ignored

tguillemin

I have the following text :

Paragraph1

Paragraph2
Paragraph2
Paragraph2
Paragraph2

Paragraph3
Paragraph3

Paragraph4```

I want to merge the lines of each paragraph, in order to get :

Paragraph1

Paragraph2 Paragraph2 Paragraph2 Paragraph2

Paragraph3 Paragraph3

Paragraph4 

Thanks to Stackoverflow, I found a solution which passes the Regex101 test

But I cannot make it work in Editorial's Find/Replace (and I did not forget to choose Regular Expression…)

What do I get wrong ?

ccc

I tend to just avoid regex like the plague that it is...

s.replace('\n\n', '<<<!?!>>>').replace('\n', ' ').replace('<<<!?!>>>', '\n\n')
tguillemin

First of all, thank you very much for your answer.

Three remarks

1) I am a Python newbie… How do I insert this in a workflow ? Through "RunPython script", I suppose (coming after an "Extend Selection" to the whole document ?), but how ?

2) How come a sequence \b\n\b in Find and a space in Replace does not work, although it works perfectly well in Regex101 ?
Could it be a bug ? I doubt it. I most certainly make a mistake, but where ?

3) I do not (entirely) share your condemnation of Regexes, but, as you know, nobody is perfect…

Thanks again