Josip Dorvak
Josip Dorvak

Reputation: 131

Letters from a-z 1-4 times followed by any digit 4-7 times

For my regex, I want letters from a-z 1-4 times followed by any digit 4-7 times. The combination of these two should have 8 characters total. something like this

([a-z]{1,4}[0-9]{4,7}){8}

I know this is wrong. Can anyone tell me the right regex expression to make this work

Upvotes: 2

Views: 55

Answers (1)

hwnd
hwnd

Reputation: 70732

You can use a lookahead based regular expression to assert the string length is exactly eight characters.

^(?=.{8}$)[a-z]{1,4}\d{4,7}$

Explanation | Live Demo

Upvotes: 2

Related Questions