Community
    • Login

    REGEX: a single line should contain each word in a paragraph.

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    8 Posts 6 Posters 983 Views 2 Watching
    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.
    • Vasile CarausV Offline
      Vasile Caraus
      last edited by

      as seen below, each line in all the paraphrases is unfinished. The words at the beginning of each line in the paragraph are not a continuation of the previous line. I’m interested in connecting all the lines in the paraphrase without having any word breaks.

      When the water rises up to F, the piece at A will be visible; when it
      reaches G, both A and B will be visible; and when it comes up to H,
      all three pieces will be visible.
      
      
      _Artificial Earthquake and Volcano._
      
      Grind an equal quantity of fresh iron filings with pure sulphur, till
      the whole be reduced to a fine powder. Be careful not to let any wet
      come near it. Then bury about thirty pounds of it a foot deep in the
      earth, and in about six or eight hours the ground will heave and
      swell, and shortly after send forth smoke and flames like a burning
      mountain. If the earth is raised in a conical shape, it will be no bad
      miniature resemblance of one of the burning mountains.
      
      
      _Artificial Illuminations._
      
      A very pleasing exhibition may be made with very little trouble or
      expense, in the following manner: Provide a box, which you fit up with
      architectural designs cut out on pasteboard; prick small holes in
      those parts of the building where you wish the illuminations to
      appear, observing, that in proportion to the perspective, the holes
      are to be made smaller; and on the near objects the holes are to be
      made larger. Behind these designs thus perforated, you fix a lamp or
      candle, but in such a manner that the reflection of the light shall
      only shine through the holes; then placing a light of just sufficient
      brilliance to show the design of the buildings before it, and making a
      hole for the sight at the front end of the box, you will have a very
      tolerable representation of illuminated buildings.
      

      THE OUTPUT

      When the water rises up to F, the piece at A will be visible; when it reaches G, both A and B will be visible; and when it comes up to H, all three pieces will be visible.
      
      
      _Artificial Earthquake and Volcano._
      
      Grind an equal quantity of fresh iron filings with pure sulphur, till the whole be reduced to a fine powder. Be careful not to let any wet come near it. Then bury about thirty pounds of it a foot deep in the earth, and in about six or eight hours the ground will heave and swell, and shortly after send forth smoke and flames like a burning mountain. If the earth is raised in a conical shape, it will be no bad miniature resemblance of one of the burning mountains.
      
      
      _Artificial Illuminations._
      
      A very pleasing exhibition may be made with very little trouble or expense, in the following manner: Provide a box, which you fit up with architectural designs cut out on pasteboard; prick small holes in those parts of the building where you wish the illuminations to appear, observing, that in proportion to the perspective, the holes are to be made smaller; and on the near objects the holes are to be made larger. Behind these designs thus perforated, you fix a lamp or candle, but in such a manner that the reflection of the light shall only shine through the holes; then placing a light of just sufficient brilliance to show the design of the buildings before it, and making a hole for the sight at the front end of the box, you will have a very tolerable representation of illuminated buildings.
      

      My regex doesn’t work very good:

      FIND: ^(.*?)$(\K.*)\r

      REPLACE BY: \2

      OR (a better one)

      FIND: ^(.*?)$(\R)

      REPLACE BY: \1

      Paul WormerP 1 Reply Last reply Reply Quote 0
      • wonkawillyW Offline
        wonkawilly
        last edited by wonkawilly

        Can you show the end line char that separates a line with the next one? Usually You could have one of the following:

        \r\n
        \r
        \n

        For example you could do something like:

        find: \r\n\r\n
        replace: §§

        then:
        find: \r\n
        replace: " " [just a space without quotes]

        then back:
        find: §§
        replace: \r\n\r\n

        1 Reply Last reply Reply Quote 1
        • CoisesC Offline
          Coises
          last edited by

          Find: ([^\r\n])\R([^\r\n])
          Replace: \1 \2

          Vasile CarausV 1 Reply Last reply Reply Quote 4
          • Vasile CarausV Offline
            Vasile Caraus @Coises
            last edited by Vasile Caraus

            @Coises very good answer, thanks a lot !

            Find what: \R+_.+_\R+(*SKIP)(*FAIL)|\R

            Replace with: LEAVE A BLANK SPACE

            1 Reply Last reply Reply Quote 0
            • guy038G Online
              guy038
              last edited by

              Hello, @Vasile-caraus, @wonkawilly, @coises and All,

              @vasile-caraus, an alternate and more simple solution could be :

              • SEARCH (?-s)(?<=.)\R(?=.)

              • REPLACE \x20

              Best Regards,

              guy038

              1 Reply Last reply Reply Quote 1
              • Vasile CarausV Offline
                Vasile Caraus
                last edited by

                Search: (?<=[^\r\n])\r?\n(?=[^\r\n])

                Replace by: leave an empy space

                1 Reply Last reply Reply Quote 0
                • Paul WormerP Offline
                  Paul Wormer @Vasile Caraus
                  last edited by

                  @Vasile-Caraus Maybe I’m missing the point, but it seems to me that an easy solution is by standard N++. One can select whatever piece of text one wants and then hit ctrl+j. This will join all lines in the selected text, creating a single (long) line.

                  Alan KilbornA 1 Reply Last reply Reply Quote 0
                  • Alan KilbornA Online
                    Alan Kilborn @Paul Wormer
                    last edited by

                    @Paul-Wormer said in REGEX: a single line should contain each word in a paragraph.:

                    Maybe I’m missing the point

                    The point you may be missing is that the OP probably has a lot of data to act upon, making doing it “by hand” impractical.

                    1 Reply Last reply Reply Quote 0

                    Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                    Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                    With your input, this post could be even better 💗

                    Register Login
                    • First post
                      Last post
                    The Community of users of the Notepad++ text editor.
                    Powered by NodeBB | Contributors