wolfz
wolfz

Reputation: 25

Regex match defined length number broken up by spaces/hyphens

I would like to match all alphanumeric strings [a-zA-Z0-9]+ with length of {4,34}, however they may be randomly broken up by spaces or hyphens. The length is the quantity of alphanumeric digits, not hyphens or spaces.

For example, AA99-A3-2134-22-5 would fit this expression, as the quantity of alphanumeric characters is >4 and <34. If this is possible in regex please help me out, I have tried grouping but am not too familiar with regex in the first place. Thanks!

Upvotes: 1

Views: 26

Answers (1)

Toto
Toto

Reputation: 91508

Have a try with:

^(?:-?[a-zA-Z0-9]){4,34}-?$

Upvotes: 1

Related Questions