Reputation: 541
I need to get rid of date formats in over 6000 lines of code. The format is always the same, but dates and times will vary including AM/PM.
This is the pattern
[10/6/17, 11:13:52 AM]
So far I used
.+?(?=[0-9])
which grabs numbers but now I am stuck. Can anyone help? Thanks!
Upvotes: 1
Views: 48
Reputation: 15012
Try this:
(?i:(\[\d{1,2}\/\d{1,2}\/\d{1,2},\s+\d{1,2}:\d{1,2}:\d{1,2}\s+[AP]M\]))
My regex is a full match with no capturing group and case insensitive. Try it. Then choose the answer you prefer.
Upvotes: 2
Reputation: 860
It depends on how strict you need to be and the boundary conditions. Something like
\[\d{1,2}\/\d{1,2}\/\d{1,2}, \d{1,2}:\d{2}:\d{2} \w{2}\]
should do it.
Btw, regex101.com is an awesome tool for debuging regexs
Upvotes: 1
Reputation: 24802
This should match your dates :
\[\d{1,2}/\d{1,2}/\d{1,2}, \d{1,2}:\d{1,2}:\d{1,2} [AP]M\]
Note that depending on the language you might need to escape the /
.
Upvotes: 0