Search code examples
regexregex-group

Isolate the day from the date into Group 1


I have a regex which works fine with leading 0s on the date but, I cannot assume to have a leading 0. The second thing is the day should be in group 1. The API is looking for the day in that group.

Also it's a sticky match

String: 2020.7.12-qui

Case 1: RegEx https://regexr.com/57cea (Works with leading 0 but, fails on non leading 0)

.*.(0?[1-9]|[12]\d|3[01])-.* 

Case 2: RegEx regexr.com/57cft (Works on non leading 0 but, fails on double digit)

.*.(0[1-9]|[12]\d|3[01])-.*

Solution

  • prably just need to escape the dot .*\.([12]\d|3[01]|0?[1-9])-.*
    becuase the day is seperaterd by a dot to left and a dash to right.