I need a regular expression that makes sure a string does not start with or end with a space. I don\'t care if it has a space in the \"middle\" just not at the beginning or the
You use lookaround assertions, because they're zero-width:
^(?=\S).*(?<=\S)$
It might be better to use negative assertions and positive character classes, though:
^(?!\s).*(?<=\s)$