Search code examples
regexvb.netstring.net-2.0

Regex to find alphanumeric match with day part of datetime


I have to match string like "DAY1","DAY2","DAY3"....."DAY31" with regex in vb.net. I tried something like this - ^?DAY(0[1-9]|[12][0-9]|3[01])$ but it did not work. Please help.

The pattern should have succesfull match if the source string is either DAY1 or DAY2 or DAY3 to DAY31 like so.


Solution

  • Try following regex (removed the ? and the 0 before the first number):

    ^DAY([1-9]|[12][0-9]|3[01])$