how to split a string with whitespace but ignore specific whitespace (that includes comma) in python
<p>I want split a string with whitespace but ignore specific whitespace (that includes comma).</p>

<p>Example: </p>

<pre><code>str = "abc de45+ Pas hfa, underak (333)"
</code></pre>

<p><strong>Required split</strong>:</p>

<pre><code>Item 1: abc
Item 2: de45+
Item 3: Pas hfa, underak
Item 4: (333)
</code></pre>

<p>If you want to split only at a space, then simply use <code>split()</code></p>

<pre><code>a = "abc de45+ Pas hfa, underak (333)"
split_str = a.split(' ')    #Splits only at space
</code></pre>

<p>If you want to split at spaces but not period, as suggested by @Beloo, use regex</p>

<pre><code>import re

a = "abc de45+ Pas hfa, underak (333)"
split_str = re.split(' ' , a)    #Splits just at spaces
split_str = re.split('[ .:]', a)    #Splits at spaces, periods, and colons
split_str = re.split('(?&lt;!,)[ ]' , a)    #Splits at spaces, excluding commas
</code></pre>

<p>As you might have guessd, if you want to exclude a character, simply put it in between the <code>(?&lt;!</code> and <code>)</code></p>

python regex