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
  • 846
  • 8
  • 19
  • 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
  • 117,272
  • 11
  • 49
  • 86
0
/^\d\d\d\d-\d\d-\d\d/ 

or

/^\d{4}-\d{2}-\d{2}/
cigien
  • 55,661
  • 11
  • 60
  • 99
Andre Marasca
  • 260
  • 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