Regex: Select and Delete all content of file, except “DATE” format

后端 未结 1 1644
予麋鹿
予麋鹿 2021-01-26 21:01

I have a file with many dates in the format of 03/07/2017.

For exemple:

My lovely letter can\'t be read...

academicsdire

相关标签:
1条回答
  • 2021-01-26 21:25

    You may use

    Find What: (\d{1,2}/\d{1,4}/\d{1,4})|.
    Replace With: (?{1}$1\n:) . matches newline: On

    Note: You may also add word boundaries around the date pattern to make it a bit more precise, \b(\d{1,2}/\d{1,4}/\d{1,4})\b|..

    Now, (\d{1,2}/\d{1,4}/\d{1,4}) will match and capture the date into Group 1 and if not found at the current location, . will match any char there. In the replacement pattern, the date is replaced with itself and a newline is added after it, and if Group 1 is not matched, the char is just removed.

    0 讨论(0)
提交回复
热议问题