• Login
Community
  • Login

How do i merge lines (Pt. 3)

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
10 Posts 5 Posters 2.3k 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.
  • F
    Faisal Alam
    last edited by Dec 11, 2020, 10:18 AM

    Sorry I should’ve shared this information in the first place so it wasn’nt clear from the start. My sincere apologies, please do have a look at my current information i hope this time it is clear.
    @PeterJones @TERRY R

    What I gave in the first place:

    3040
    Woodsidi
    5202
    Sivilli Rd
    6406
    W 81 ST
    1853
    Yukon Ct
    

    Result came from @PeterJones 's Regex:

    3040 Woodsidi
    5202 Sivilli Rd
    6406 W 81 ST
    1853 Yukon Ct
    

    My actual txt:

    3040
    Woodsidi
    56897
    246971692
    (236) 526 2626
    5202
    Sivilli Rd
    56897
    246971692
    (236) 526 2626
    6406
    W 81 ST
    56897
    246971692
    (236) 526 2626
    1853
    Yukon Ct
    56897
    246971692
    (236) 526 2626
    

    Result came from @PeterJones 's Regex:

    3040 Woodsidi
    56897 246971692
    (236) 526 2626
    5202 Sivilli Rd
    56897 246971692
    (236) 526 2626
    6406 W 81 ST
    56897 246971692
    (236) 526 2626
    1853 Yukon Ct
    56897 246971692
    (236) 526 2626
    

    Result I wanted/expected:

    3040 Woodsidi
    56897
    246971692
    (236) 526 2626
    5202 Sivilli Rd
    56897
    246971692
    (236) 526 2626
    6406 W 81 ST
    56897
    246971692
    (236) 526 2626
    1853 Yukon Ct
    56897
    246971692
    (236) 526 2626
    

    Thank you already :)

    A 1 Reply Last reply Dec 11, 2020, 11:05 AM Reply Quote 1
    • A
      astrosofista @Faisal Alam
      last edited by Dec 11, 2020, 11:05 AM

      Hi @Faisal-Alam

      As long as data provided is representative of the full text — but only you know that —, the following regex meets your needs:

      Search: \R(?![\d(])
      Replace: \x20
      

      Put the caret at the very beginning of the document, select just the Regular Expressions mode and click on Replace All.

      Have fun!

      F 1 Reply Last reply Dec 11, 2020, 12:35 PM Reply Quote 3
      • F
        Faisal Alam @astrosofista
        last edited by Dec 11, 2020, 12:35 PM

        @astrosofista thanks man! It really worked ❤️ but i still can not use this as my txt actually comprises some other words which i am not posting here because I’m afraid people will call me childish and won’t help anymore. But this way also my work isn’t going to done. If you’re willing to help me through my work then i will post it and if not then no problem. Anyways thank you buddy you really nailed it. Sad for me i can not use this.

        A A 3 Replies Last reply Dec 11, 2020, 1:08 PM Reply Quote -2
        • A
          astrosofista @Faisal Alam
          last edited by Dec 11, 2020, 1:08 PM

          Hi @Faisal-Alam

          I see. You may want to take another approach. Can you elaborate a criterium covering all the relevant details to guide our regex efforts? For example, the criterium I used before was: Replace a LN/CR \R by a space \x20 as long as it is not followed ?=! by a number \d or an open parenthesis (.

          Have fun!

          1 Reply Last reply Reply Quote 1
          • A
            Alan Kilborn @Faisal Alam
            last edited by Dec 11, 2020, 1:10 PM

            @Faisal-Alam said in How do i merge lines (Pt. 3):

            Sad for me i can not use this

            Yep, sad for you.

            Also, can you stop opening a new thread each time you want to add something to this overall topic? Just reply within the thread and the site will keep all these common postings together under one heading.

            F 1 Reply Last reply Dec 11, 2020, 2:10 PM Reply Quote 2
            • F
              Faisal Alam @Alan Kilborn
              last edited by Dec 11, 2020, 2:10 PM

              @Alan-Kilborn I’m really a newbie here, i use to make my own regex for each barrier i get but I’m unable to do this one so i came here followed by google. Anyways thanks, I’ll keep that in mind next time.

              1 Reply Last reply Reply Quote 1
              • A
                Alan Kilborn @Faisal Alam
                last edited by Dec 11, 2020, 2:13 PM

                @Faisal-Alam said in How do i merge lines (Pt. 3):

                my txt actually comprises some other words

                I’m surprised that this statement by the OP hasn’t pushed @PeterJones over the edge… :-)

                P 1 Reply Last reply Dec 11, 2020, 2:18 PM Reply Quote 1
                • P
                  PeterJones @Alan Kilborn
                  last edited by Dec 11, 2020, 2:18 PM

                  @Alan-Kilborn ,

                  hasn’t pushed @PeterJones over the edge

                  Well, I just found this third topic in the discussion a minute ago, so I hadn’t gotten that far. And since other people had taken over answering, I’ll just ♫Let It Go♫

                  1 Reply Last reply Reply Quote 2
                  • G
                    guy038
                    last edited by guy038 Dec 11, 2020, 4:49 PM Dec 11, 2020, 4:48 PM

                    Hello, @faisal-alam, @terry-r, @peterjones, @alan-kilborn, @astrosofista and All,

                    @faisal-alam :

                    An other regex solution, which gives an output text identical to @astrosofista’one, would be :

                    SEARCH ^\d{4}\K\R

                    REPLACE \x20

                    Notes :

                    • My search regex ^\d{4}\K\R approach is to find only the lines whose the line-break must be changed as a space char :

                      • Searches from beginning ( ^ ) of line for a number with 4 digits ( \d{4} )

                      • Then the \K syntax cancelled everything that matched so far and, then, it searches for the **line break character(s) ( \R ) at the end of that specific line…

                      • Which is replaced by a space character ( \x20 )


                    • The @astrosofista’s search regex \R(?![\d(]) approach is to find a line break which is not followed with a number or bracket :

                      • Searches for line-ending characters ( \r or \n ) but ONLY IF  the look-ahead structure (?!......) is true

                      • So, IF NOT  followed with, either :

                        • A digit \d

                        • An opening bracket (

                      • Which is replaced by a space character ( \x20 )


                    If these two S/R do not give you the expected text, simply provide us some more substantial data to aim the needed text changes to perform by a regex S/R ;-))

                    Best Regards,

                    guy038

                    F 1 Reply Last reply Dec 13, 2020, 12:21 PM Reply Quote 2
                    • F
                      Faisal Alam @guy038
                      last edited by Dec 13, 2020, 12:21 PM

                      @guy038 Damn brother this worked perfectly tysm

                      1 Reply Last reply Reply Quote 2
                      6 out of 10
                      • First post
                        6/10
                        Last post
                      The Community of users of the Notepad++ text editor.
                      Powered by NodeBB | Contributors