RegEx for no whitespace at the beginning and end 1

RegEx for no whitespace at the beginning and end

^[^\s]+(\s+[^\s]+)*$

Here is what the above code is Doing:
1. ^ – Matches the beginning of the string.
2. [^\s]+ – Matches one or more non-whitespace characters.
3. (\s+[^\s]+)* – Matches zero or more sequences of one or more whitespace characters followed by one or more non-whitespace characters.
4. $ – Matches the end of the string.

Similar Posts