-1

I'd like to make a reglar expression which checks date digit e.g. 1 through 31. I think it has three patterns : [0-9], [12][0-9], 3[01].

But I don't know how to make them as one regex with |(or) operator.

Anybody has idea for this?

tripleee
  • 175,061
  • 34
  • 275
  • 318

2 Answers2

1

Updated:

([0-2][0-9]|(3)[0-1])

Hope this answer your question

Shai
  • 117
  • 6
  • 19
1

What you need is alternation and a group to make the pattern local. Just use a | within the capture group (a|b) or non-capturing group (?:a|b):

([1-9]|[12][0-9]|3[01])
Thomas Ayoub
  • 29,063
  • 15
  • 95
  • 142