I want to design an expression for not allowing whitespace at the beginning and at the end of a string, but allowing in the middle of the string.
The regex I\'ve tri
How about:
^\S.+\S$
This will match any string that doesn't begin or end with any kind of space.
pattern="^[^\s]+[-a-zA-Z\s]+([-a-zA-Z]+)*$" This will help you accept only characters and wont allow spaces at the start nor whitespaces.
^[^\s].+[^\s]$
That's it!!!! it allows any string that contains any caracter (a part from \n) without whitespace at the beginning or end; in case you want \n in the middle there is an option s that you have to replace .+
by [.\n]+
As a modification of @Aprillion's answer, I prefer:
^\S$|^\S[ \S]*\S$
This is the regex for no white space at the begining nor at the end but only one between. Also works without a 3 character limit :
\^([^\s]*[A-Za-z0-9]\s{0,1})[^\s]*$\
- just remove {0,1} and add *
in order to have limitless space between.
^[^0-9 ]{1}([a-zA-Z]+\s{1})+[a-zA-Z]+$
-for No more than one whitespaces in between , No spaces in first and last.
^[^0-9 ]{1}([a-zA-Z ])+[a-zA-Z]+$
-for more than one whitespaces in between , No spaces in first and last.