RegEx for no whitespace at the beginning and end

This should work: ^[^\s]+(\s+[^\s]+)*$ If you want to include character restrictions: ^[-a-zA-Z0-9-()]+(\s+[-a-zA-Z0-9-()]+)*$ Explanation: the starting ^ and ending $ denotes the string. considering the first regex I gave, [^\s]+ means at least one not whitespace and \s+ means at least one white space. Note also that parentheses () groups together the second and third fragments … Read more