How to strip date / time in Notepad ++ (regular expressions)


The task is to remove the date or time in the log file, for example, this:

[11:33] hello
[11:35] how to replace timestamp with a space?
[12:16] probably this can be done using regular expressions
[12:44] I tried period (.) But nothing comes out
[15:12] how to remove numbers from the log?

To do this, we turn to the (my favorite) Notepad ++ editor which is free and open-source.

Press ctrl+h, and choose “Regular expressions”; in the upper field put this: 

\[\d{2}:\d{2}\]

‘\’ – will screen bracket ‘[‘ , because in regular expressions such symbols used for assigning parameters, so you have to screen them;
‘\d’ – this is regular expression for any number from 0 to 9
{2} – gives number of symbols on which regular expression will be applied

So, ‘\d{2}’ – will replace two number symbols.

The same way with the date, eg:

2018-11-08 16:58:16 how to remove the date and time from the log?
2018-11-08 17:02:51 replace any numbers

To do so we use:

\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}


Additionally some more useful expressions:

^[#].*
delete all strokes which starts with #

[\r\n]+
delete new stroke (\n)

^[ \t]*$\r?\n
replace empty strokes on something (eg on ‘A’)

For example, we need to change values in expressions which got new stroke symbol:

?:[AND [EQU $CLASS Mage] [EQU $RACE Damned] [EQU $GENDER Female] ]
RF:<player>:0x97:0x81

Regex:

Damned] \[EQU \$GENDER Female] ]
RF:<player>:0x\w{2}:0x\w{2}

Change at:

Damned] [EQU $GENDER Female] ]\r\nRF:<player>:0x97:0x81

 

Good luch! Will be glad to see your comments! 🙂


This entry was posted in Notepad++ (en). Bookmark the permalink.

Leave a Reply

🇬🇧 Attention! Comments with URLs/email are not allowed.
🇷🇺 Комментарии со ссылками/email удаляются автоматически.