Regular expression for rounding a date with quotation marks

I have a list of all the data in the same format that I need to analyze in Weka.

I need to surround the date / time values โ€‹โ€‹with quotation marks "", but cannot generate a regular expression to complete it.

I need to change the line:

1028,NULL,1,21,7,AD9,06A,60136859,NULL,1,4,3,2012-02-21 10:05:00.100,2012-02-21 10:05:23.170 

to a line like this:

 1027,NULL,1,21,7,AD9,06A,60136859,NULL,1,5,4,"2012-02-21 10:03:53.643","2012-02-21 10:04:29.787" 

where date / time values โ€‹โ€‹are surrounded by quotation marks.

+4
source share
1 answer

This will work in notepad ++ if your datetime values โ€‹โ€‹are always fully formatted.

 Find what: (\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.\d{3}) Replace with: "\1" 

This works because of backlinks. Everything that is fixed in parentheses is stored as a backlink. You access backlinks by typing \number , where the number correlates with the position of the brackets in the regular expression. Therefore, since we use only one pair of brackets, we want to get backlink 1, and we use \1 .

So, you will find the entire date , and it is stored in \1 due to the bracket in your regex. Then you replace the entire date with "entire date" aka "\1" .

+4
source

Source: https://habr.com/ru/post/1444471/


All Articles