Community
    • Login

    Advance Replace including right trim (repost with example)

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    15 Posts 6 Posters 383 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.
    • Mike AlbersM
      Mike Albers @guy038
      last edited by Mike Albers

      @guy038 Hi Guy, i think your solution is working after all.
      in the tool something strange happens. But in Notepad it seems to work properly.
      I tried it out on the testfile with the \n characters in the 4th field.
      Now i will try it on my real life CSV file to see what happens there.

      So far so good.

      Thanks!

      Alan KilbornA 1 Reply Last reply Reply Quote 1
      • Alan KilbornA
        Alan Kilborn @Mike Albers
        last edited by

        @Mike-Albers said:

        I tried out your solution with the online regex tool at regex101 site but it is not working.

        Some of these regexes are quite “involved”. The more involved they are, the less likely they are to work in both regex101 and Notepad++; the reason for this is that they use different regular expression engines and all engines have nuanced processing when the regexes are not simple. It may not be the case here, but you should try all advice provided in Notepad++'s replace before coming to a conclusion.

        Mike AlbersM 1 Reply Last reply Reply Quote 0
        • Alan KilbornA
          Alan Kilborn @guy038
          last edited by Alan Kilborn

          @guy038

          This post has 7 revisions

          As I typed my reply, I kept seeing screen flashes, so I investigated.
          It appears that Guy is uber-editing his earlier response.
          Hopefully, he’s not changing history, and and is always making harmless edits.
          Otherwise, how is @Mike-Albers to “keep up” with the advice being provided?


          EDIT: Now:

          This post has 8 revisions

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

            Hello, @alan-kilborn and All,

            I agree that I edited my previous post a lot of times.

            But it’s just because if you just paste the INPUT text in a new tab, you get all the sentences with a final line-break = \r\n

            And, of course, the regex S/R would not work in this case :-((

            BR

            guy038

            1 Reply Last reply Reply Quote 0
            • Mike AlbersM
              Mike Albers @Alan Kilborn
              last edited by

              @Alan-Kilborn you are right. I jumped to conslusions.
              Tried in notepad++ and the solution from guy seems to work after all. Changed the reply asap. :-)

              PeterJonesP 1 Reply Last reply Reply Quote 1
              • PeterJonesP
                PeterJones @Mike Albers
                last edited by PeterJones

                @Alan-Kilborn said,

                It appears that Guy is uber-editing his earlier response

                @Mike-Albers said,

                Changed the reply asap

                In general, my preference is that posts not get edited after there’s a reply, because that breaks the flow of the conversation. In extreme circumstances, if there is an edit after a reply, I highly encourage marking it like “edit: xyz” or similar, or, if there’s a bunch of information that turns out to be wrong, using the ~~~ to strikethrough, like, “old incorrect information [edited: see my reply below]” . This allows people to be able to see what was being responded to in the immediate replies, but informs them that something has been updated.

                It should be noted that even changing a post before there are any replies is dangerous, because someone may have read your original, and maybe even replying with quoting your original text, and having your text now be different makes it look like the person is misquoting you, which they are not actually doing.

                (This discussion has a case in point: Alan quoted the regex101 line, and now it’s been edited away.)

                As said in another forum where I spend a lot of time, “It is uncool to update a [post] in a way that renders replies confusing or meaningless”.

                Alan KilbornA 1 Reply Last reply Reply Quote 2
                • Alan KilbornA
                  Alan Kilborn @PeterJones
                  last edited by

                  @PeterJones

                  Amen. Don’t change posts after posting them, unless you are 100% sure you aren’t changing any meaning. That is, only change an obvious typo (but NOT one in an “expression”). Otherwise, follow Peter’s excellent advice.

                  1 Reply Last reply Reply Quote 0
                  • mkupperM mkupper referenced this topic on
                  • Mike AlbersM
                    Mike Albers @guy038
                    last edited by Mike Albers

                    @guy038 Hi guy, I studied your solution and Regex itself and it starts to dawn at me.
                    I changed my testfile and tried in addition how to handle empty fields. For that i changed your searchstring a tiny bit but also added an extra OR clause.
                    It seems to work properly now.

                    My latest testfile was like this:
                    TESTFILE_02.JPG

                    My search pattern is now:
                    (?s)^(?:[^\r\n;];){3}.{0,24}\r\n|^((?:[^\r\n;];){3}.{0,24}).?\r\n|^(?:[^\r\n;]?)\r\n

                    The replace statement is still yours:
                    ?1$1\r\n:$0

                    Result was:
                    File_after_replace.JPG

                    I tried to figure out the replace string, but i don’t get it.
                    (tried selfstudy on it with Regex0101 tool bit by bit but since it is not 100% compatible i couldn’t figure it out myself.) Really no lazyness on my part here when i ask my question.
                    So i hope you can explain it step by step for me.

                    Thanks!

                    Mike AlbersM 1 Reply Last reply Reply Quote 0
                    • Mike AlbersM
                      Mike Albers @Mike Albers
                      last edited by PeterJones

                      @Mike-Albers
                      Addition for people that will use this final solution in an Oracle database:
                      I had memo-fields in my export CSV-file that were restricted to 4000 CHAR positions. (default is max 4000 in bytes)
                      The regex-search was:

                      (?s)^(?:[^\r\n;]*;){N}.{0,3996}\r\n|^((?:[^\r\n;]*;){N}.{0,3996}).*?\r\n|^(?:[^\r\n;]*?)\r\n
                      

                      N normal fields + 1 memo-field that contains linefeeds in the text.

                      In Oracle i created an external file based on the CSV-file with truncated memo field.
                      It proofed impossible to read 4000 characters because the \r\n is taken into the fieldvalue.
                      Once in Oracle the linefeeds are counted as single characters, but i think that is based on codeset-settings. When counting the length of the oracle CHAR(4000 CHAR) field i found a max length of 3970 instead of 3996 as my truncate position.
                      Keep this in mind otherwise you will get problems with reject limits.

                      —

                      moderator added code markdown around text; please don’t forget to use the </> button to mark example text as “code” so that characters don’t get changed by the forum

                      Alan KilbornA 1 Reply Last reply Reply Quote 0
                      • Alan KilbornA
                        Alan Kilborn @Mike Albers
                        last edited by

                        @Mike-Albers said:

                        (?s)^(?:[^\r\n;];){N}.{0,3996}\r\n|^((?:[^\r\n;];){N}.{0,3996}).?\r\n|^(?:[^\r\n;]?)\r\n

                        Unfortunately, your regular expression was corrupted because you didn’t post it correctly.
                        Probably a moderator will come along and examine your “raw” original post and correct it.

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