• Login
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.
  • V
    Vegard Johansen
    last edited by Jun 15, 2023, 8:27 AM

    Hello

    I’m new to this program but i have a large document with many dates like this “23032022”, and i want it to be like this: “20222303” - I hope there’s is anyone that could help me here?

    A 1 Reply Last reply Jun 15, 2023, 10:18 AM Reply Quote 0
    • A
      Alan Kilborn @Vegard Johansen
      last edited by Jun 15, 2023, 10:18 AM

      @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

      G 1 Reply Last reply Jun 15, 2023, 10:27 AM Reply Quote 1
      • W
        wonkawilly
        last edited by wonkawilly Jun 15, 2023, 10:25 AM Jun 15, 2023, 10:23 AM

        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
        • G
          gerdb42 @Alan Kilborn
          last edited by gerdb42 Jun 15, 2023, 10:32 AM Jun 15, 2023, 10:27 AM

          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

          V 2 Replies Last reply Jun 15, 2023, 9:19 PM Reply Quote 4
          • V
            Vegard Johansen @gerdb42
            last edited by Jun 15, 2023, 9:19 PM

            @gerdb42 Thanks for this:) worked perfectly :)

            1 Reply Last reply Reply Quote 0
            • V
              Vegard Johansen @gerdb42
              last edited by Vegard Johansen Jun 19, 2023, 10:15 AM Jun 19, 2023, 10:14 AM

              @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
              • G
                guy038
                last edited by guy038 Jun 19, 2023, 11:24 AM Jun 19, 2023, 10:57 AM

                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

                V 1 Reply Last reply Jun 19, 2023, 11:14 AM Reply Quote 1
                • V
                  Vegard Johansen @guy038
                  last edited by Jun 19, 2023, 11:14 AM

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

                  A 1 Reply Last reply Jun 19, 2023, 11:17 AM Reply Quote 0
                  • A
                    Alan Kilborn @Vegard Johansen
                    last edited by Jun 19, 2023, 11:17 AM

                    @Vegard-Johansen

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

                    Maybe show what you did here.

                    V 1 Reply Last reply Jun 20, 2023, 6:56 AM Reply Quote 0
                    • V
                      Vegard Johansen @Alan Kilborn
                      last edited by Jun 20, 2023, 6:56 AM

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

                      P 1 Reply Last reply Jun 20, 2023, 8:24 AM Reply Quote 0
                      • P
                        Paul Wormer @Vegard Johansen
                        last edited by Paul Wormer Jun 20, 2023, 8:25 AM Jun 20, 2023, 8:24 AM

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

                        V 1 Reply Last reply Jun 20, 2023, 11:36 AM Reply Quote 1
                        • V
                          Vegard Johansen @Paul Wormer
                          last edited by Jun 20, 2023, 11:36 AM

                          @Paul-Wormer Hello

                          Its part of the input :)

                          P 1 Reply Last reply Jun 20, 2023, 12:39 PM Reply Quote 0
                          • P
                            Paul Wormer @Vegard Johansen
                            last edited by Jun 20, 2023, 12:39 PM

                            @Vegard-Johansen

                            Find: "(-?\d+)\x20(\d+)"   Replace:  "\1\2"
                            
                            V 1 Reply Last reply Jun 20, 2023, 1:17 PM Reply Quote 1
                            • V
                              Vegard Johansen @Paul Wormer
                              last edited by Jun 20, 2023, 1:17 PM

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

                              P 1 Reply Last reply Jun 20, 2023, 2:01 PM Reply Quote 0
                              • G
                                guy038
                                last edited by guy038 Jun 20, 2023, 2:45 PM Jun 20, 2023, 1:26 PM

                                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

                                V 1 Reply Last reply Jun 20, 2023, 1:54 PM Reply Quote 2
                                • V
                                  Vegard Johansen @guy038
                                  last edited by Jun 20, 2023, 1:54 PM

                                  @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

                                  P 1 Reply Last reply Jun 20, 2023, 2:05 PM Reply Quote 0
                                  • P
                                    Paul Wormer @Vegard Johansen
                                    last edited by Paul Wormer Jun 20, 2023, 2:08 PM Jun 20, 2023, 2:01 PM

                                    @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
                                    • P
                                      PeterJones @Vegard Johansen
                                      last edited by Jun 20, 2023, 2:05 PM

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

                                      V 1 Reply Last reply Jun 20, 2023, 2:09 PM Reply Quote 0
                                      • V
                                        Vegard Johansen @PeterJones
                                        last edited by Jun 20, 2023, 2:09 PM

                                        @PeterJones @guy038 replace.jpg

                                        P 1 Reply Last reply Jun 20, 2023, 2:18 PM Reply Quote 0
                                        • P
                                          PeterJones @Vegard Johansen
                                          last edited by PeterJones Jun 20, 2023, 2:22 PM Jun 20, 2023, 2:18 PM

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

                                          P V 2 Replies Last reply Jun 20, 2023, 2:23 PM Reply Quote 3
                                          9 out of 27
                                          • First post
                                            9/27
                                            Last post
                                          The Community of users of the Notepad++ text editor.
                                          Powered by NodeBB | Contributors