title: PHP - Improve Regex (space and non-capturing group)
body: <p>I have this kind of string :</p>
  
  <pre><code>$string = "&lt;strong&gt;Blabla1&lt;/strong&gt; Blaabla2&lt;br /&gt; Blaabla3 &lt;strong&gt;Blaabla4&lt;/strong&gt; Blaabla5 Blaabla6&lt;br /&gt;&lt;br /&gt; Blaabla7 &lt;span style='color:#B22222;'&gt;Blaabla8&lt;/span&gt; Blaabla9";
  </code></pre>
  
  <p>I'm trying to explode each word where there is a <code>" "</code> or <code>"&lt;br /&gt;"</code> with <code>preg_split</code> . </p>
  
  <p><strong>My conditions :</strong></p>
  
  <p>For each word (<code>Blablax</code>), I need to keep his tags like <code>&lt;strong&gt;</code>, <code>&lt;span&gt;</code>, <code>&lt;em&gt;</code>... but split him after a <code>&lt;br /&gt;</code> or more <code>&lt;br /&gt;</code></p>
  
  <p>I tried this, thanks to another post on stackoverflow :</p>
  
  <pre><code>preg_split('/&lt;br(\s\/)?&gt;\K|\s/',$string,null,PREG_SPLIT_NO_EMPTY);
  </code></pre>
  
  <p><strong>OUTPUT:</strong></p>
  
  <pre><code>array (size=12)
    0 =&gt; string '&lt;strong&gt;Blabla1&lt;/strong&gt;' (length=24)
    1 =&gt; string 'Blaabla2&lt;br /&gt;' (length=14)
    2 =&gt; string 'Blaabla3' (length=8)
    3 =&gt; string '&lt;strong&gt;Blaabla4&lt;/strong&gt;' (length=25)
    4 =&gt; string 'Blaabla5' (length=8)
    5 =&gt; string 'Blaabla6&lt;br /&gt;' (length=14)
    6 =&gt; string '&lt;br' (length=3)
    7 =&gt; string '/&gt;' (length=2)
    8 =&gt; string 'Blaabla7' (length=8)
    9 =&gt; string '&lt;span' (length=5)
    10 =&gt; string 'style='color:#B22222;'&gt;Blaabla8&lt;/span&gt;' (length=38)
    11 =&gt; string 'Blaabla9' (length=8)
  </code></pre>
  
  <p>Everything works <strong>except</strong> for <code>index 6</code> and <code>index 7</code> (see above in OUTPUT) and <code>index 9</code> and <code>index 10</code></p>
  
  <p><strong>What I'll exepect :</strong></p>
  
  <pre><code>array (size=12)
        0 =&gt; string '&lt;strong&gt;Blabla1&lt;/strong&gt;' (length=24)
        1 =&gt; string 'Blaabla2&lt;br /&gt;' (length=14)
        2 =&gt; string 'Blaabla3' (length=8)
        3 =&gt; string '&lt;strong&gt;Blaabla4&lt;/strong&gt;' (length=25)
        4 =&gt; string 'Blaabla5' (length=8)
        5 =&gt; string 'Blaabla6&lt;br /&gt;&lt;br /&gt;' (length=14)
        6 =&gt; string 'Blaabla7' (length=8)
        7 =&gt; string '&lt;span style='color:#B22222;'&gt;Blaabla8&lt;/span&gt;' (length=45)
        8 =&gt; string 'Blaabla9' (length=8)
  </code></pre>
  
  <p>See <code>index 5</code> and  <code>index 7</code></p>
  
  <p>My regex works if I have just one <code>&lt;br /&gt;</code> but if more than one, there is a mistakes... idem if I have a <code>&lt;span style...&gt;</code></p>
  
  <p>Thanks !</p>