How to check at least one regular expression

I can check a string if it observes this format "XXw XXd XXh XXm" using the following Regex:

(\d{1}|\d{2})w (\d{1}|\d{2})d (\d{1}|\d{2})h (\d{1}|\d{2})m

XX: whole numbers

I want to check if there is at least one of XXw, XXd, XXh, XXm in the string, any way to do it via Regex?

+3


source to share


1 answer


(?=.*?\d{1,2}[wdhm])

      



You can add a simple lookahead

one to check this.

+1


source







All Articles