Reputation: 319
I want to know regular expression will be most effective to achieve the following:
In a date and time stamp string, I want to remove the time stamp if it is just zeros. But the problem is the time stamp can have multiple formats. For example:
2013-02-04 00:00:00
2013-02-04 00:00:00.0
2013-02-04 00:00 AM
2013-02-04 00:00 PM
Thanks
Upvotes: 0
Views: 744
Reputation: 5344
For each line:
line.replaceAll("(00:?)+(.0)?\s*([AP]M)", "");
( // start time group
00 // strange timestamp symbol
:? // allow ':'
)+ // strange group can be repeated more than one time
(.0)? // if ms was specified
\s* // allow spaces before AM,PM
( // AM, PM group
[AP] // A or P letter
M // M
)? // AP, PM group can not exists
Upvotes: 2