Community
    • Login

    Line combination

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    13 Posts 7 Posters 1.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.
    • Terry RT
      Terry R @madison assessor
      last edited by Terry R

      @madison-assessor said in Line combination:

      Is there a way to use the replace function to combine the lines between each set of quotations?

      There is a way, it uses regular expressions to find the lines that don’t have the trailing “quotes” and change the end of line to something else. I will add that Notepad++ isn’t adding in the quotes, they are in the file that Notepad++ is opening.

      Before we can provide a solution, you need to provide what you would like to see after the change is made. In respect of removing the end of lines, do you want a comma, some other character, what?

      Terry

      PS How about read the post pinned to the start of this forum group called “Please read this before posting”

      madison assessorM 1 Reply Last reply Reply Quote 2
      • madison assessorM
        madison assessor @Terry R
        last edited by

        This post is deleted!
        Lycan ThropeL 1 Reply Last reply Reply Quote 0
        • Lycan ThropeL
          Lycan Thrope @madison assessor
          last edited by

          @madison-assessor ,
          You’ve misunderstood @Terry-R request that you read the FAQ. You need to provide the information so it can be pulled from your message and used to test variations on. Pictures are useless unless as a showing of a result.

          For text transformations that you can’t do on your own, you need to provide that in a code enclosed formatting, which shows you didn’t read the FAQ. Please read it “before posting”, thank you.

          PeterJonesP madison assessorM 2 Replies Last reply Reply Quote 0
          • PeterJonesP
            PeterJones @Lycan Thrope
            last edited by PeterJones

            here’s your freebie, @madison-assessor . Just understand that @Terry-R really was hoping you’d read the FAQ more closely, and provide data that we could copy/paste so we could verify our solution before posting, as @Lycan-Thrope seconded. We cannot very well run a regex on an image of text.

            freebie:
            FIND = (?<!")\r\n
            REPLACE = \x20
            MODE = Regular expression

            unsolicited advice: if you don’t have those people’s permission, you probably shouldn’t be posting any data about them in a public forum.

            ----

            Useful References

            • Please Read Before Posting
            • Template for Search/Replace Questions
            • Formatting Forum Posts
            • Notepad++ Online User Manual: Searching/Regex
            • FAQ: Where to find other regular expressions (regex) documentation
            PeterJonesP 1 Reply Last reply Reply Quote 3
            • madison assessorM
              madison assessor @Lycan Thrope
              last edited by

              This post is deleted!
              1 Reply Last reply Reply Quote 1
              • guy038G
                guy038
                last edited by guy038

                Hi, All,

                I’ve found out exactly the same regex S/R than @Peterjones !

                But, just for fun, can you understand why this similar syntax below, does not work properly ?

                I mean for people using Windows EOL … ( Use the ¶ icon in the Tool Bar )

                SEARCH (?<!")\R

                REPLACE \x20

                BR

                guy038

                Terry RT 1 Reply Last reply Reply Quote 1
                • PeterJonesP
                  PeterJones @PeterJones
                  last edited by

                  I said,

                  if you don’t have those people’s permission, you probably shouldn’t be posting any data about them in a public forum

                  As a result, the intervening posts and the original screenshot were deleted without any dummy text being used to replace it, making it harder for future readers to see what the regex applies to.

                  BEFORE

                  "FAKENAME FAKENAME X OR
                  FAKENAME FAKENAME
                  9876 W 9876 S
                  CITYNAME ST  12345"
                  "FAKENAME FAKENAME X
                  9876 W 9876 S
                  CITYNAME ST  12345"
                  "FAKENAME FAKENAME
                  9876 N 9876 W
                  CITYNAME ST  12345"
                  "FAKENAME FAKENAME FAKENAME
                  FAKENAME FAKENAME
                  + Additional Owners and/or Contacts
                  9876 BLAH
                  DIFFERENT CITY ST  12345"
                  

                  AFTER:

                  "FAKENAME FAKENAME X OR FAKENAME FAKENAME 9876 W 9876 S CITYNAME ST  12345"
                  "FAKENAME FAKENAME X 9876 W 9876 S CITYNAME ST  12345"
                  "FAKENAME FAKENAME 9876 N 9876 W CITYNAME ST  12345"
                  "FAKENAME FAKENAME FAKENAME FAKENAME FAKENAME + Additional Owners and/or Contacts 9876 BLAH DIFFERENT CITY ST  12345"
                  
                  1 Reply Last reply Reply Quote 1
                  • Terry RT
                    Terry R @guy038
                    last edited by

                    @guy038 said in Line combination:

                    But, just for fun, can you understand why this similar syntax below, does not work properly ?

                    @guy038 how does this sound?

                    Writing this as a sentence we have “find a position in the text such that the character immediately before the caret is NOT a quote (as specified) and the character following the caret is within the \R set of characters.”
                    So the last bit is most important as \R can be a carriage return (CR), a line feed (LF), both (CRLF) or some other special characters as defined here.

                    Normally \R will capture both the CR and the LF, but with the addition of the “cannot have a quote before the caret” the regular expression engine moves it’s caret to between the CR and the LF, thus making the code TRUE. So now it has captured ONLY the LF. In making the replacement we are left with a CR on the previous line with a space following. Notepad++ will show the result which appears to be correct, each record on a separate line (CR isn’t a valid line ending for Windows files), but there is also a space starting most records.

                    Terry

                    Alan KilbornA 1 Reply Last reply Reply Quote 2
                    • guy038G
                      guy038
                      last edited by guy038

                      Hi, @madison-assessor, @terry-r, @peterjones and All,

                      Well… first of all, let’s remember the definition of the \R syntax :

                      \R = (?>\r\n|\n|\x0b|\f|\r|\x85|\x{2028}\x{2029}), which is an atomic group of some alternatives, representing 2 or 1 line-break character(s)

                      Practically, with the Boost Regex engine, we can approximate this syntax as below :

                      \R = \r\n|\n|\r


                      So, given this simple text, ending with the XYZ string followed with a double-quotes character, the \r\n EOL characters and a new line beginning with the string ABC :

                      FIRST  line :     ... XYZ"CRLF
                                            12345 6
                      SECOND line :     ABC ...
                      

                      and the equivalent regex :

                      SEARCH (?<!")(?:\r\n|\r|\n)

                      • When the regex engine position is at positions 1 to 4, there’s obviously no match as current character is not a line-break

                      • When the regex engine position is at position 5 the first alternative \r\n could be OK but is preceded with a " char, so no match again, as well as with the two other alternatives \r and \n !

                      • When the regex engine position is at position 6, only the third alternative \n does match because it’s a line-break which is not preceded with a " char ( actually it’s the \r char ! )

                      => Thus, the first line-break \r remains right after the " character and the second line-break \n is replaced with a space character beginning a new line :

                      FIRST  line :     ... XYZ"CR
                                        ... 12345
                      SECOND line :      ABC ...
                                        1234 ...
                      

                      Best Regards,

                      guy038

                      P.S. :

                      Of course, if we change the search regex as :

                      SEARCH (?<!")\r\n

                      This time, no ambiguity remains : we do search for the two characters \r\n, in this order, if the \r char is not preceded with a " character !

                      1 Reply Last reply Reply Quote 0
                      • Alan KilbornA
                        Alan Kilborn @Terry R
                        last edited by Alan Kilborn

                        @Terry-R said in Line combination:

                        Normally \R will capture both the CR and the LF, but with the addition of the “cannot have a quote before the caret” the regular expression engine moves it’s caret to between the CR and the LF, thus making the code TRUE. So now it has captured ONLY the LF. In making the replacement we are left with a CR on the previous line with a space following. Notepad++ will show the result which appears to be correct, each record on a separate line (CR isn’t a valid line ending for Windows files), but there is also a space starting most records.

                        Terry seems to have “nailed it” with this.

                        Maybe the moral of the story is, be careful with \R, or perhaps just don’t even use it. Be aware of your file’s end-of-line type, and just use the corresponding \r\n or \n (or even \r) in your expressions. In practicality, how often does a user switch between end-of-line types for different files in their daily work, anyway?

                        1 Reply Last reply Reply Quote 3
                        • Mark OlsonM
                          Mark Olson
                          last edited by

                          Why not just (?:\r?\n|\r), since that gets all three possible line endings?

                          PeterJonesP 1 Reply Last reply Reply Quote 0
                          • PeterJonesP
                            PeterJones @Mark Olson
                            last edited by

                            @Mark-Olson ,

                            Why not just … ?

                            In this specific instance? Because it shares the same problem as \R in this instance: if your real text is "\r\n, then (?<!")(?:\r?\n|\r) will match between the \r and the \n in the file.

                            In general? Because in the vast majority of plaintext files, everything it matches is also matched by \R, which is so much easier to type.

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