I have a form field in which I want to allow 1 to 50 letters, numbers, and spaces in it. Just not start with a space and ends with a space. (Or, alternatively, if it starts with a space, it's not counted toward 50.)
I have something like:
^[^s][a-zA-Z0-9_ ]{1,50}[^s]$
But something like "AB" now doesn't pass, because nothing match the {1,50}.
EDIT:
The regex is for the HTML input element pattern field.
s- guess you want anything but\s(whitespace). And that you can do with\S(capital S) -^\S[a-zA-Z0-9_ ]{1,50}\S$.^\s*[a-zA-Z0-9_ ]{1,50}\s*$which allows white space in the beginning and at the end, without them being included in the 50. (The logic of) Your regex requires white space in the beginning and the end.^[^\s][a-zA-Z0-9_ ]{1,50}\b$or^\b[\w ]{1,50}\b$regex101.com/r/lE5hS9/1