Reputation: 2831
I have got the following regular expression and I want to extract the data type and length into groups so that I can act on them.
^(an|a|n)\..([0-9]*)|(an|a|n)([0-9]*)
The following data types are all valid:
an..70
- meaning alphanumerics up to 70 characters longan3
- meaning alphanumeric exactly 3 characters longn4
- numeric containing four digitsn..4
- numeric containing up to four digitsOnly 'an' 'n' and 'n' are the valid data types and all can have a '..' range indicator between the type and the number (or not).
The issue I am having is the regular expression doesn't work when I process 'ang..35' since it's matching 'an' in the text, but I want this to be invalid if it cannot find any of the valid data types.
Upvotes: 0
Views: 173
Reputation: 665121
when I process 'ang..35' it's matching 'an' in the text but I want it to be invalid
Then you also want to use an $
end-of-string anchor.
For example:
/^(a?n)((?:\.\.)?\d+)$/
Upvotes: 1