• Login
Community
  • Login

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

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
8 Posts 6 Posters 370 Views
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.
  • V
    Vasile Caraus
    last edited by Jun 15, 2023, 8:12 AM

    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

    P 1 Reply Last reply Jun 21, 2023, 8:32 AM Reply Quote 0
    • W
      wonkawilly
      last edited by wonkawilly Jun 15, 2023, 11:18 AM Jun 15, 2023, 11:11 AM

      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
      • C
        Coises
        last edited by Jun 15, 2023, 4:39 PM

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

        V 1 Reply Last reply Jun 15, 2023, 8:41 PM Reply Quote 4
        • V
          Vasile Caraus @Coises
          last edited by Vasile Caraus Jun 15, 2023, 8:56 PM Jun 15, 2023, 8:41 PM

          @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
          • G
            guy038
            last edited by Jun 16, 2023, 12:01 AM

            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
            • V
              Vasile Caraus
              last edited by Jun 21, 2023, 7:43 AM

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

              Replace by: leave an empy space

              1 Reply Last reply Reply Quote 0
              • P
                Paul Wormer @Vasile Caraus
                last edited by Jun 21, 2023, 8:32 AM

                @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.

                A 1 Reply Last reply Jun 21, 2023, 10:55 AM Reply Quote 0
                • A
                  Alan Kilborn @Paul Wormer
                  last edited by Jun 21, 2023, 10:55 AM

                  @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
                  3 out of 8
                  • First post
                    3/8
                    Last post
                  The Community of users of the Notepad++ text editor.
                  Powered by NodeBB | Contributors