title: How can I check a string with regex until I find a whitespace?
body: <p>I have this regex with the preg_replace function on PHP :</p>
  
  <pre><code>$str=preg_replace(
      '#\b((Hello ).+)#',
      '&lt;a class="lforum" href="$1"&gt;$1&lt;/a&gt;',
      $str);
  </code></pre>
  
  <p>It checks all strings that start with <code>Hello</code> and are followed by any kind of chars (at least one char, with repetition).</p>
  
  <p>So for example :</p>
  
  <pre><code>Hello Mark \\ is checked
  HelloMark  \\ is not checked
  </code></pre>
  
  <p>The problem now is that also this string is checked :</p>
  
  <pre><code>Hello Mark Cordi
  </code></pre>
  
  <p>because white space is a char, anyway. </p>
  
  <p>I don't want this. Or, better, if the string is <code>Hello Mark Cordi</code>, it must replace only <code>Hello Mark</code>.</p>
  
  <p>How can I do this? Thanks</p>
  
  <p><strong>EDIT</strong> Problem with newline</p>
  
  <p>My actual function :</p>
  
  <pre><code>echo example(htmlentities($myString, ENT_QUOTES, "UTF-8"));
  
  function example($str) {
      $str=preg_replace(
          '#((Hello )[^ \n]+)#',
          '&lt;a class="lforum" href="$1"&gt;$1&lt;/a&gt;',
          $str);
  
      return nl2br($str);     
  }
  </code></pre>
  
  <p>If $myString is :</p>
  
  <pre><code>Hello Mario
  Ciao
  </code></pre>
  
  <p>(notice the newline, so at the end of Hello Mario there is a \n) the output is this :</p>
  
  <pre><code>&lt;a class="lforum" href="Hello Mario&lt;br /&gt;"&gt;Hello Mario&lt;br /&gt;&lt;/a&gt;&lt;br /&gt;Ciao
  </code></pre>
  
  <p>instead of :</p>
  
  <pre><code>&lt;a class="lforum" href="Hello Mario"&gt;Hello Mario&lt;/a&gt;&lt;br /&gt;Ciao
  </code></pre>
  
  <p>So it add that \n with $1 on replace, and it shouldnt :(</p>