Based on oschlueter's answer and Nick ODell's comment, the following does the job:
[s.replace('\\','') for s in re.split(r'(?<!\\):', parser['sites']['urls'])]
re.split
returns the capture group – the negative lookbehind in this case – so you need to remove it with str.replace
.
>>> import re
>>> from configparser import ConfigParser
>>> parser = ConfigParser()
>>> parser.read('config.ini')
['config.ini']
>>> [s.replace('\\','') for s in re.split(r'(?<!\\):', parser['sites']['urls'])]
['https://google.com', 'https://yahoo.com', 'https://gmail.com']
EDIT:
Works with other delimiters too:
urls_at=https://google.com/\@@https://yahoo.com/\@@https://gmail.com/\@
urls_semicolon=https://google.com/\;;https://yahoo.com/\;;https://gmail.com/\;
>>> [s.replace('\\','') for s in re.split(r'(?<!\\);', parser['sites']['urls_semicolon'])]
['https://google.com/;', 'https://yahoo.com/;', 'https://gmail.com/;']
>>> [s.replace('\\','') for s in re.split(r'(?<!\\)@', parser['sites']['urls_at'])]
['https://google.com/@', 'https://yahoo.com/@', 'https://gmail.com/@']