Reputation: 477
If I need to find a regex that matches any positive number of lower case characters, an N
, and then either 6 integers, 8 integers or 15 integers. But not match any other number of intagers
e.g. "abcN123456" or "abcdN12345678" or "abN123456789012345" or "abcdefgN123456"
How would you make a regex that finds this?
It starts with [a-z]+N
but don't know how to do the variable number of integers
Upvotes: 0
Views: 247
Reputation: 4906
Here's a possible solution
^[a-z]+N(?:\d{6}|\d{8}|\d{15})$
or try this "crazier" variant ;)
^[a-z]+N(?:\d{6}|(?:(?:\d{7}){1,2}\d))$
Upvotes: 2