title: Easiest validation regular expression not matching space at beginning or end
body: <p>I'm trying to find the easiest validation regular expression (PCRE) for use in method preg_match() in PHP. I want to keep it as easy as possible and avoid repetition if possible.</p>
  
  <p>My matching criteria in words is:</p>
  
  <ul>
  <li><p>Allow one or more characters (this implies string should be 1 characters and up in total) from the following list:</p>
  
  <pre><code>a-zA-Z0-9 +&amp;-
  </code></pre></li>
  <li>Do not allow space in beginning or end</li>
  </ul>
  
  <p>My regular expression knowledge might be lacking but what I come up with without the second space criterion is:</p>
  
  <pre><code>    /^[a-zA-Z0-9 +&amp;-]+$/
  </code></pre>
  
  <p>To not match space I'm thinking about something like</p>
  
  <pre><code>    /^[^ ]+[a-zA-Z0-9 +&amp;-]+[^ ]+$/
  </code></pre>
  
  <p>but this actual piece would need 3+ characters.</p>
  
  <p>If I do</p>
  
  <pre><code>    /^[^ ]*[a-zA-Z0-9 +&amp;-]+[^ ]*$/
  </code></pre>
  
  <p>it will not work at all times either, I suppose it has to do with the "greediness" of the middle part, but I've really tried to research how to get it right without succeeding.</p>
  
  <p>Thankful for any kind of advice or pointer in the right direction!</p>