Regular expression to limit number of characters to 10
You can use curly braces to control the number of occurrences. For example, this means 0 to 10:
/^[a-z]{0,10}$/
The options are:
- {3} Exactly 3 occurrences;
- {6,} At least 6 occurrences;
- {2,5} 2 to 5 occurrences.
See the regular expression reference.
Your expression had a + after the closing curly brace, hence the error.
/^[a-z]{0,10}$/
should work. /^[a-z]{1,10}$/
if you want to match at least one character, like /^[a-z]+$/
does.
It might be beneficial to add greedy matching to the end of the string, so you can accept strings > than 10 and the regex will only return up to the first 10 chars. /^[a-z0-9]{0,10}$?/
grep '^[0-9]\{1,16\}' | wc -l
Gives the counts with exact match count with limit