0

I have dates that are in m/d/yy but need to convert them to yyyy-dd-mm format. I have the following regex (\d{1,2})\/(\d{1,2})\/(\d{1,2}) with this replace 20$3-$1-$2. I'm assuming year 2000 which is okay but this breaks for single digit days and months.

Is there any way to prefix the days and months with 0 if the match is on a single digit?

purplecones
  • 77
  • 1
  • 9
  • Are you working this in PHP? –  Jul 13 '18 at 12:34
  • The expression will be evaluated in the browser via Javascript using the `Regex()` implementation. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions – purplecones Jul 13 '18 at 13:13

1 Answers1

1

It might be usefull for you. Add zero padding to single digit dates: Regex to add leading zero in date record

  • Thanks. Is this a Notepad++ only implementation? I can't seem to get it to work in https://regex101.com. – purplecones Jul 13 '18 at 13:14
  • Notepad++ uses Perl/PCRE syntax regexp. You just need to replace different marks in Perl style for JS regex syntax style. It might be usefull: https://www.regextester.com/6 In this site: https://regex101.com/ you have few types of syntax pcre(php), javascript, python, golang. Try to test it all :) – Mateusz Byczkowski Jul 13 '18 at 13:52