omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    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

    Editorial
    2
    3
    2182
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • tguillemin
      tguillemin last edited by

      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 ?

      1 Reply Last reply Reply Quote 0
      • ccc
        ccc last edited by

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

        s.replace('\n\n', '<<<!?!>>>').replace('\n', ' ').replace('<<<!?!>>>', '\n\n')
        
        1 Reply Last reply Reply Quote 0
        • tguillemin
          tguillemin last edited by

          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

          1 Reply Last reply Reply Quote 0
          • First post
            Last post
          Powered by NodeBB Forums | Contributors