3

I've an application log whith timestamps from 01-24 (instead of 00-23), I'm trying to do a search and replace "24" with "00" eg

15.03.2012 24:59:58 - SIRENG INFO  com.app.funnction.info
15.03.2012 01:01:02 - SIRENG INFO  com.app.funnction.moreinfo

Should return

15.03.2012 00:59:58 - SIRENG INFO  com.app.funnction.info
15.03.2012 01:01:02 - SIRENG INFO  com.app.funnction.moreinfo

So far i've got

([0-9+]+).([0-9]+).([0-9\.$]+) ([0-9]+):([0-9]+):([0-9]+)

Tim Pietzcker
  • 328,213
  • 58
  • 503
  • 561
  • I love to share this link for anyone having issues with regex's http://gskinner.com/RegExr/ realtime regex creation just copy text to window and watch it go as you build the regex.. – dc5553 Apr 23 '12 at 12:58
  • Also a good rule of thumb to follow make your regex as specific as possible ie. first number goes no farther than 2 right? so use [0-2] not [0-9] not a killer in this situation just good to practice to use this always. – dc5553 Apr 23 '12 at 13:02
  • 2
    I've edited your question (you want to change "24" to "00", not "23"). But one question remains: Are you sure that the `24:nn:nn` time doesn't have yesterday's date as compared to `00:nn:nn`? – Tim Pietzcker Apr 23 '12 at 13:05

1 Answers1

1

Search for this regex

([0-9]+\.[0-9]+\.[0-9]{4}) 24:([0-9]+:[0-9]+)

or if shorthand character classes are supported by your regex engine, you can use this regex

(\d\d\.\d\d\.\d{4}) 24:(\d\d:\d\d)

and replace it with

$1 00:$2
  • $1 = first group: ([0-9]+\.[0-9]+\.[0-9]{4}) will match 15.03.2012
  • $2 = second group: ([0-9]+:[0-9]+) will match 59:58
splash
  • 13,037
  • 1
  • 44
  • 67