Regex on bytestring in Python 3
<p>I am using RegEx to match BGP messages in a byte string. An example byte string is looking like this:</p>

<p><code>b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x13\x04\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x13\x04'</code></p>

<p>\xff (8 times) is used as "magic marker" to start a single message. Now I want to split the messages to parse each of them.</p>

<pre><code>messages = re.split(b'\xff{8}', payload)
</code></pre>

<p>Matching works fine but I got some empty fields in my messages array.</p>

<pre><code>b'' 
b''
b'001304'
b''
b''
b'001304'
</code></pre>

<p>Can someone explain this behavior? Why are there two empty fields between each (correct splitted) message. In larger byte strings sometimes there is just one empty field between each messages.</p>