Find and replace with reordered date format in notepad++

后端 未结 4 1898
失恋的感觉
失恋的感觉 2021-01-31 04:16

I have a file with a few thousand rows to be added to a MySQL database. There are date values in the rows which are in the dd-mm-yyyy format but I need them to be in the yyyy-mm

4条回答
  •  情话喂你
    2021-01-31 05:03

    To make sure you only reorder wrong formats (in case you have mixed formats from merging databases), use this:

    ([0-9]{2})-+([0-9]{2})-+([0-9]{4})
    

    This searches for (four digits, dash, two digits, dash, two digits).

    In an regex capable editor like notepad++, replace it with this:

    \3-\2-\1
    

    In a tool like libre office, you need to replace it with this:

    $3-$2-$1 
    

    Edit: I wrote a blogpost about this as it seems to be a common problem: http://bytethinker.com/blog/correct-date-format-with-notepad-and-regex

提交回复
热议问题