Find and replace with reordered date format in not

2019-03-09 02:20发布

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-dd format.

E.g., '11-04-2010', needs to become '2010-04-11', in every row.

Is there a simple way to do this in notepad++ or another text editor?

3条回答
做自己的国王
2楼-- · 2019-03-09 02:59

You can do this with Textpad:

Find: ([0-9]+)-+([0-9]+)-+([0-9]+)

Replace: \3-\2-\1

查看更多
劫难
3楼-- · 2019-03-09 03:06

Used Notepad++ to change mm/dd/yyyy to yyyy/mm/dd in several lines of a text file. Script was saved as a macro for next file.

Find: ([0-9]{2})/+([0-9]{2})/+([0-9]{4}) Replace: \3/\1/\2

查看更多
Emotional °昔
4楼-- · 2019-03-09 03:12

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

查看更多
登录 后发表回答