I am new to regex and have a problem with re.split functionality.
In my case, the split should take care of the “special shoots”.
The text should be divided into ; except that there is a lead ? .
Edit: In this case, the two parts should not be separated and ? must be deleted.
Here is an example and the result I want:
import re txt = 'abc;vwx?;yz;123' re.split(r'magical pattern', txt) ['abc', 'vwx;yz', '123']
I have tried so far this attempt:
re.split(r'(?<!\?);', txt)
and received:
['abc', 'vwx?;yz', '123']
Sadly causes an unmet problem ? , and the following list comprehension refers to critical characteristics:
[part.replace('?;', ';') for part in re.split(r'(?<!\?);', txt)] ['abc', 'vwx;yz', '123']
Is there a “quick” way to reproduce this behavior with re?
Could the re.findall function be the solution to take?
For example, an extended version of this code:
re.findall(r'[^;]+', txt)
I am using python 2.7.3.
Thank you pending!