How to split string with different phones using re?
<p>For example there are such phones:</p>

<pre><code>phones = '+35(123) 456 78 90 (123) 555 55 55  (908)985 88 89   (593)592 56 95'
</code></pre>

<p>I need to get:</p>

<pre><code>phones_list = ['+35(123) 456 78 90', '(123) 555 55 55', '(908)985 88 89', (593)592 56 95]
</code></pre>

<p>Trying to solve using <code>re</code>, but quite a hard task to me.</p>

<p>This approach uses the <code>+</code> or <code>(</code> to signal the beginning of a phone number.  It does not require multiple-spaces:</p>

<pre><code>&gt;&gt;&gt; phones = '+35(123) 456 78 90 (123) 555 55 55  (908)985 88 89   (593)592 56 95'
&gt;&gt;&gt; re.split(r' +(?=[(+])', phones)
['+35(123) 456 78 90', '(123) 555 55 55', '(908)985 88 89', '(593)592 56 95']
</code></pre>

<p>This splits the string based on one-or-more spaces followed by either <code>(</code> or <code>+</code>.</p>

<p>In the regular expression, <code>+</code> matches one or more spaces.  <code>(?=[(+])</code> is a look-ahead.  It requires that the spaces be followed by either <code>(</code> or <code>+</code> but does not consume the <code>(</code> or <code>+</code>.  Because we are using a look-ahead instead of a plain match, the the leading <code>(</code> and <code>+</code> remain part of the phone number.</p>

python regex python-3.x