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
This RegEx will allow neither white-space at the beginning nor at the end of your string/word.
^[^\s].+[^\s]$
Any string that doesn't begin or end with a white-space will be matched.
Explanation:
^ denotes the beginning of the string.\s denotes white-spaces and so [^\s] denotes NOT white-space. You could alternatively use \S to denote the same.. denotes any character expect line break.+ is a quantifier which denote - one or more times. That means, the character which + follows can be repeated on or more times.You can use this as RegEx cheat sheet.