Rules for the regex in english:
- min length = 3
- max length = 6
- only letters from ASCII table, non-numeric
My initial attempt:
[A-Za-z]{3-6}
A second attempt
\w{3-6}
This regex will be used to validate input strings from a HTML form (i.e. validating an input field).
A modification to your first one would be more appropriate
The
\bmark the word boundaries and avoid matching for example ‘abcdef’ from ‘abcdefgh’. Also note the comma between ‘3’ and ‘6’ instead of ‘-‘.The problem with your second attempt is that it would include numeric characters as well, has no word boundaries again and the hypen between ‘3’ and ‘6’ is incorrect.
Edit: The regex I suggested is helpful if you are trying to match the words from some text. For validation etc if you want to decide if a string matches your criteria you will have to use