How to split up a string on multiple delimiters but only capture some?
<p>I want to split a string on any combination of delimiters I provide. For example, if the string is:  </p>

<pre><code>s = 'This, I think,., Ú©Ø¨Ø§Ø¨ MAKES , some sense '
</code></pre>

<p>And the delimiters are <code>\.</code>, <code>,</code>, and <code>\s</code>. However I want to capture all delimiters except whitespace <code>\s</code>. The output should be:  </p>

<pre><code>['This', ',', 'I', 'think', ',.,', 'Ú©Ø¨Ø§Ø¨', 'MAKES', ',', 'some', 'sense']
</code></pre>

<p>My solution so far is is using the <code>re</code> module:  </p>

<pre><code>pattern = '([\.,\s]+)'  
re.split(pattern, s)
</code></pre>

<p>However, this captures whitespace as well. I have tried using other patterns like <code>[(\.)(,)\s]+</code> but they don't work.</p>

<p><em>Edit</em>: @PadraicCunningham made an astute observation. For delimiters like <code>Some text ,. , some more text</code>, I'd only want to remove leading and trailing whitespace from <code>,. ,</code> and not whitespace within.</p>

<p><em>Update based on OP's last edit</em></p>

<p>Python 3.*:</p>

<pre><code>list(filter(None, re.split('([.,]+(?:\s+[.,]+)*)|\s', s)))
</code></pre>

<p>Output:</p>

<pre><code>['This', ',', 'I', 'think', ',.,', 'Ú©Ø¨Ø§Ø¨', 'MAKES', ',', 'some', 'sense']
</code></pre>

python regex