3

I have the following dates:

2020-09-01,13:23:29.000+0000
2020-07-22,13:13:48.000+0000
2020-01-09,21:58:48.000+0000

I wonder how can I just keep the date in atom, the result should be like:

2020-09-01
2020-07-22
2020-01-09

I tried to find all ^(.*?)\s,.*$ and then replace by $1 which was not working.

Wiliam
  • 1,078
  • 10
  • 21
  • 4
    It does not work because there is not whitespace before the comma. This would work `^(.*?)\s*,.*$` but better use the posted pattern. – The fourth bird Feb 02 '21 at 13:22

2 Answers2

3

With your shown samples, could you please try following. Online demo is: Online regex demo

^\d{4}(?:-\d{2}){2}

Explanation: ^\d{4} checking condition if it starts with 4 digits followed by a non-capturing group of (-\d{2}){2} which means a dash followed by 2 digits and this group comes 2 times match that pattern.

RavinderSingh13
  • 130,504
  • 14
  • 57
  • 93
0
/^\d\d\d\d-\d\d-\d\d/ 

or

/^\d{4}-\d{2}-\d{2}/
cigien
  • 57,834
  • 11
  • 73
  • 112
Andre Marasca
  • 270
  • 1
  • 6
  • 2
    While this code may answer the question, providing additional context regarding why and/or how this code answers the question improves its long-term value. – Nic3500 Feb 13 '21 at 02:29