Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex to add leading zero in date record

Question - what is the shortest form of regex to add a leading zero into single digit in date record?

So I want to convert 8/8/2014 8:04:34 to 08/08/2014 8:04:34 - add leading zero when only one digit is presented.

The record can have two single digit entry, one single digit entry or no single digit entry. Some records can be in forms like 25/06/2014 19:50:18 or 9/06/2014 8:27:35 - in other words, some of them could be already normalized and regex needs to fix only single digit entry.

Not a regex user by any means. Your help is appreciated.

like image 874
Invisible999 Avatar asked May 11 '16 09:05

Invisible999


1 Answers

How about:

  • Ctrl+H
  • Find what: \b(\d)(?=/)
  • Replace with: 0$1
  • Replace all

This will change 8/8/2014 8:04:34 into 08/08/2014 8:04:34

like image 113
Toto Avatar answered Nov 15 '22 06:11

Toto