Community
    • Login

    moving year in a date from the end to the front.

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    27 Posts 7 Posters 2.4k 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.
    • Alan KilbornA
      Alan Kilborn @Vegard Johansen
      last edited by

      @Vegard-Johansen

      A possible problem is if your data has other 8-digit numbers that aren’t dates, but if it does just let us know and we’ll adjust to that. Another assumption to make is that your dates are not adjacent to other alphanumeric data, e.g., you don’t have mydate23032022.

      Keeping it simple for now… :

      Find: (\d{2}\d{2})(\d{4})
      Replace: ${2}${1}
      Search mode: Regular expression

      gerdb42G 1 Reply Last reply Reply Quote 1
      • wonkawillyW
        wonkawilly
        last edited by wonkawilly

        Hi I had a similar problem and the solution I adopted was crating a some macros to perform the conversion in many direction. Here they are:

        <Macro name="Date convert all dd-/.mm-/.yyyy → yyyy-mm-dd" Ctrl="yes" Alt="no" Shift="yes" Key="89">
                    <Action type="3" message="1700" wParam="0" lParam="0" sParam="" />
                    <Action type="3" message="1601" wParam="0" lParam="0" sParam="(\d{2})(\.|-|/)(\d{2})(\.|-|/)(\d{4})" />
                    <Action type="3" message="1625" wParam="0" lParam="2" sParam="" />
                    <Action type="3" message="1602" wParam="0" lParam="0" sParam="($5)-($3)-($1)" />
                    <Action type="3" message="1702" wParam="0" lParam="768" sParam="" />
                    <Action type="3" message="1701" wParam="0" lParam="1609" sParam="" />
                </Macro>
                <Macro name="Date convert dd.mm.yyyy → yyyy-mm-dd" Ctrl="no" Alt="yes" Shift="yes" Key="68">
                    <Action type="3" message="1700" wParam="0" lParam="0" sParam="" />
                    <Action type="3" message="1601" wParam="0" lParam="0" sParam="(\d{2})(\.)(\d{2})(\.)(\d{4})" />
                    <Action type="3" message="1625" wParam="0" lParam="2" sParam="" />
                    <Action type="3" message="1602" wParam="0" lParam="0" sParam="($5)-($3)-($1)" />
                    <Action type="3" message="1702" wParam="0" lParam="768" sParam="" />
                    <Action type="3" message="1701" wParam="0" lParam="1609" sParam="" />
                </Macro>
                <Macro name="Date convert yyyy-mm-dd → dd.mm.yyyy" Ctrl="yes" Alt="yes" Shift="yes" Key="89">
                    <Action type="3" message="1700" wParam="0" lParam="0" sParam="" />
                    <Action type="3" message="1601" wParam="0" lParam="0" sParam="(\d{4})(-)(\d{2})(-)(\d{2})" />
                    <Action type="3" message="1625" wParam="0" lParam="2" sParam="" />
                    <Action type="3" message="1602" wParam="0" lParam="0" sParam="($5).($3).($1)" />
                    <Action type="3" message="1702" wParam="0" lParam="768" sParam="" />
                    <Action type="3" message="1701" wParam="0" lParam="1609" sParam="" />
                </Macro>
        

        Notice that they are made to match my standard date format that is yyyy-mm-dd. So if needed can be freely adapted to specific use cases.

        1 Reply Last reply Reply Quote -1
        • gerdb42G
          gerdb42 @Alan Kilborn
          last edited by gerdb42

          Or, if you want to rearrange day and month as well you could use
          Search: (\d{2})(\d{2})(\d{4})
          Replace: ${3}${2}${1}

          And if you like to learn about RegExes look here

          Vegard JohansenV 2 Replies Last reply Reply Quote 4
          • Vegard JohansenV
            Vegard Johansen @gerdb42
            last edited by

            @gerdb42 Thanks for this:) worked perfectly :)

            1 Reply Last reply Reply Quote 0
            • Vegard JohansenV
              Vegard Johansen @gerdb42
              last edited by Vegard Johansen

              @gerdb42 Hello again, I have another problem. in a large document i have some lines like this: “-4 497” and like this: “17 787” i want to remove the space? do you know how?

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

                Hello, @Vegard-Johansen, @gerdb42, @alan-kilborn, @wonkawilly and All,

                I think that a correct answer could be :

                • SEARCH (?<=\d)\x20+(?=\d)

                • REPLACE Leave EMPTY

                Best Regards,

                guy038

                Vegard JohansenV 1 Reply Last reply Reply Quote 1
                • Vegard JohansenV
                  Vegard Johansen @guy038
                  last edited by

                  @guy038 Im sorry but i didnt get that to work :(

                  Alan KilbornA 1 Reply Last reply Reply Quote 0
                  • Alan KilbornA
                    Alan Kilborn @Vegard Johansen
                    last edited by

                    @Vegard-Johansen

                    Did you make sure Search Mode was set to Regular expression?

                    Maybe show what you did here.

                    Vegard JohansenV 1 Reply Last reply Reply Quote 0
                    • Vegard JohansenV
                      Vegard Johansen @Alan Kilborn
                      last edited by

                      @Alan-Kilborn Hello

                      I have a large document that look like this:

                      “120000” “various” “646958” “20220323” “12” “firstname lastname” “-4 497” “20220407” “646958”

                      And i want to remove the space in: “-4 497”

                      Paul WormerP 1 Reply Last reply Reply Quote 0
                      • Paul WormerP
                        Paul Wormer @Vegard Johansen
                        last edited by Paul Wormer

                        @Vegard-Johansen Are the double quotes part of your input? Or did you put them in as a clarification of your question?

                        In general, it is clearest and easiest when you cut and paste the relevant part of your actual input into a codeblock (triggered by </>).

                        Vegard JohansenV 1 Reply Last reply Reply Quote 1
                        • Vegard JohansenV
                          Vegard Johansen @Paul Wormer
                          last edited by

                          @Paul-Wormer Hello

                          Its part of the input :)

                          Paul WormerP 1 Reply Last reply Reply Quote 0
                          • Paul WormerP
                            Paul Wormer @Vegard Johansen
                            last edited by

                            @Vegard-Johansen

                            Find: "(-?\d+)\x20(\d+)"   Replace:  "\1\2"
                            
                            Vegard JohansenV 1 Reply Last reply Reply Quote 1
                            • Vegard JohansenV
                              Vegard Johansen @Paul Wormer
                              last edited by

                              @Paul-Wormer did not work :( maybe i do something wrong :(

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

                                Hello, @Vegard-Johansen, @gerdb42, @alan-kilborn, @wonkawilly, @paul-wormer and All,

                                May be I should have given more details on my regex S/R !


                                So :

                                • Start N++ and open your document

                                • Open the Replace dialog ( Ctrl + H )

                                • Uncheck all box options

                                • Enter (?<=\d)\x20+(?=\d) in the Find what : zone

                                • Verify that the Replace with : zone is EMPTY

                                • Check the Wrap around box

                                • Select the Regular expression search mode

                                • Click on the Replace All button

                                => All the Space characters, which exist within numbers, should have disappeared !

                                • Save the changes

                                Best Regards,

                                guy038

                                Vegard JohansenV 1 Reply Last reply Reply Quote 2
                                • Vegard JohansenV
                                  Vegard Johansen @guy038
                                  last edited by

                                  @guy038 said in moving year in a date from the end to the front.:

                                  (?<=\d)\x20+(?=\d)

                                  sorry but i cant understand what im doing wrong… But i cant get it to work :I

                                  PeterJonesP 1 Reply Last reply Reply Quote 0
                                  • Paul WormerP
                                    Paul Wormer @Vegard Johansen
                                    last edited by Paul Wormer

                                    @Vegard-Johansen Did you include the double quotes in both the Find expression and the Replace expression? Did you have exactly one space between the digits? Did you check the regex mode box?

                                    My regex is a sort of brute force solution, I capture quotes and digits before and after a single space and copy them without a space in between them. @guy038 has a more sophisticated solution. He matches one (or more) space(s) that are surrounded by one digit on the left and one digit on the right and replaces the matching space(s) by an empty string.

                                    However, both methods work. I have tried them both.

                                    1 Reply Last reply Reply Quote 1
                                    • PeterJonesP
                                      PeterJones @Vegard Johansen
                                      last edited by

                                      @Vegard-Johansen said in moving year in a date from the end to the front.:

                                      i cant understand what im doing wrong

                                      Could you give us a screenshot of your “Replace” dialog when you’re trying to use one of those regular expressions? We can probably figure out what setting you forgot to include.

                                      Vegard JohansenV 1 Reply Last reply Reply Quote 0
                                      • Vegard JohansenV
                                        Vegard Johansen @PeterJones
                                        last edited by

                                        @PeterJones @guy038 replace.jpg

                                        PeterJonesP 1 Reply Last reply Reply Quote 0
                                        • PeterJonesP
                                          PeterJones @Vegard Johansen
                                          last edited by PeterJones

                                          @Vegard-Johansen ,

                                          Your Replace dialog looked right, so I went to your original post and (using my moderator powers) looked at the text you typed rather than what the forum rendered. When I copied from there and pasted into Notepad++, I saw
                                          535477dc-b5fe-4be0-adb7-cb552a2f1bec-image.png

                                          Please notice that the character between the -4 and the 497 is not a space; it is the special character NBSP (Non-breaking space). Because you said “i want to remove the space”, and did not accurately tell us what character was between there, we could not derive a regex that works. The \x20 in the regular expression only applies to the normal ASCII space character, not to a tab or to a NBSP or to any other space-like character.

                                          If your Notepad++ is not showing the NBSP symbol, then make sure you are on a relatively-recent Notepad++ version (v8.5 or newer), and make sure that View > Show Symbol > Show Non-printing Characters is turned on (has a checkmark next to it):
                                          563035f8-cebc-4d8d-a28c-d92d99133d9c-image.png

                                          But back to your question:

                                          Since we now know it’s a non-breaking space, we can change @guy038’s regular expression to (?<=\d)\xA0+(?=\d), and that will match just if there’s a non-breaking space between those characters. If there might be any horizontal space (real space, tab, nbsp, or others), then use (?<=\d)\h+(?=\d) instead, to make it match on any horizontal space.

                                          This shows the importance of knowing (and sharing) what the actual characters are.

                                          Paul WormerP Vegard JohansenV 2 Replies Last reply Reply Quote 3
                                          • Paul WormerP
                                            Paul Wormer @PeterJones
                                            last edited by

                                            @PeterJones Good catch! I started to suspect something like that. Would we have seen it if he had cut and pasted his input into a code block?

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