0

This seems simple but I am not very familiar with regex so I'm having hard time finding a solution.

I have a date/time in string format that looks like this:

"11/18/2022 12:00 AM"

I want to create another property that is just a day ahead (so "11/19/2022 12:00 AM"), so I need a regex expression that just points to the "18" in that string.

Any help or guidance is appreciated! Thanks.

I've tried this:

^(.)(.)(./[^/])$

which just replaces the whole string.

1 Answers1

0

You could match the pattern with capture groups and use those groups in the replacement.

The value for 18 is in capture group 2, and the leading and trailing part in group 1 and group 3 in case you want to do a replacement.

^(\d{1,2}/)(\d{1,2})(/\d{4}\s\d{1,2}:\d{1,2}\s[AP]M)$

See a regex 101 demo

Note that when you want to increment the date with a day, it would be better to match the string and then use a programming language with a date function/api.

The fourth bird
  • 154,723
  • 16
  • 55
  • 70