title: How to match word surronded by spaces OR at the end / beginning of the string using Perl regexp?
body: <p>I want to find sequences matching my regexp should they be in the middle of the string surrounded by spaces, in the end or beginning or be the only thing in a string.</p>
  
  <p><strong>Example:</strong>
  Let's assume the sequence <code>'qwe45rty'</code> is what we are looking for. I want to be able to get positive on all of these strings:</p>
  
  <p><code>'qwe45rty'</code> <code>'qwe45rty blabla'</code> <code>'smth qwe45rty blabla'</code> <code>'smth qwe45rty'</code> <code>' qwe45rty '</code></p>
  
  <p>But none of these:</p>
  
  <p><code>'aaqwe45rty'</code> <code>'qwe45rtybb'</code> <code>'aaqwe45rtybb'</code></p>
  
  <p>Best what I came up with is smth like this:</p>
  
  <pre class="lang-perl prettyprint-override"><code>if ( ($a =~ /\s+$re\s+/) or
       ($a =~ /^$re\s+/)   or
       ($a =~ /\s+$re$/)   or
       ($a =~ /^$re$/)        )
  {
      # do stuff
  }
  </code></pre>
  
  <p>which can't be the best way to do that :)</p>
  
  <p>Any suggestions?</p>