re.split() with special cases
Question: I am new to regular expression and have a problem with the re.split
functionality.

In my case the split has to care "special escapes".

The text should be seperated at `;`, except there is a leading `?`.

**Edit:** In that case the two parts shouldn't be splitted and the `?` has to
be removed.

Here an example and the result I wish:

    
    
    import re
    txt = 'abc;vwx?;yz;123'
    re.split(r'magical pattern', txt)
    ['abc', 'vwx;yz', '123']
    

I tried so far these attempt:

    
    
    re.split(r'(?<!\?);', txt)
    

and got:

    
    
    ['abc', 'vwx?;yz', '123']
    

Sadly causes the not consumed `?` trouble and the following list comprehension
is to performance critical:

    
    
    [part.replace('?;', ';') for part in re.split(r'(?<!\?);', txt)]
    ['abc', 'vwx;yz', '123']
    

Is there a "fast" way to reproduce that behavior with re?

Could the re.findall function be the solution to take?

For example a extended version of this code:

    
    
    re.findall(r'[^;]+', txt)
    

I am using python 2.7.3.

Thanking you in anticipation!


Answer: Regex is not the tool for the job. Use the `csv` module instead:

    
    
    >>> txt = 'abc;vwx?;yz;123'
    >>> r = csv.reader([txt], delimiter=';', escapechar='?')
    >>> next(r)
    ['abc', 'vwx;yz', '123']
    

