title: regex pattern to match only strings that don't contain spaces PHP
body: <p>I want to match the word/pattern that is contained in the variable, but only match against the words that don't have white spaces. Please give suggestions.</p>
  
  <blockquote>
    <p>$var = 'look'; </p>
    
    <p>$array = ('look', 'greatlook',
    'lookgreat', 'look great', 'badlook',
    'look bad', 'look    ', '    look');</p>
  </blockquote>
  
  <p>matches words: look, greatlook, lookgreat, badlook</p>
  
  <p>non matches: look great, bad look, look (trailing space(s)), (space(s)) look.</p>
  
  <p>The syntax of the below functions are OK, but it matches everything</p>
  
  <blockquote>
    <p>$match = preg_grep ("/$var/", $array);</p>
    
    <p>$match = preg_grep ("/^$var/",
    $array); (match words with 'look' at the start)</p>
  </blockquote>
  
  <p>but when I include the [^\s], it gives an error</p>
  
  <p>$match = preg_grep ("/$var[^\s]/", $array);</p>
  
  <p>Parse error: syntax error, unexpected '^', expecting T_STRING or T_VARIABLE </p>
  
  <p>TIA</p>