Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Problem with Find/Replace regex : \n (newline) and \b (boundary) ignored
-
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 ?
-
I tend to just avoid regex like the plague that it is...
s.replace('\n\n', '<<<!?!>>>').replace('\n', ' ').replace('<<<!?!>>>', '\n\n')
-
First of all, thank you very much for your answer.
Three remarks
-
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 ?
-
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 ? -
I do not (entirely) share your condemnation of Regexes, but, as you know, nobody is perfect…
Thanks again
-