Regular Expression IGNORECASE different for findall and split?
__peter__ at web.de
Tue Sep 6 22:13:30 CEST 2005
> >>> re.split('x', '1x2X3', re.I)
> ['1', '2X3']
> I expected ['1', '2', '3'] but in this case re.I bahaves exactly as not
> present at all...
> Is that an expected behaviour or a fault?
This is expected:
Help on function split in module sre:
split(pattern, string, maxsplit=0)
Split the source string by the occurrences of the pattern,
returning a list containing the resulting substrings.
You are setting maxsplit to
Use re.compile() to get the desired behaviour:
>>> re.compile("x", re.I).split("1x2X3")
['1', '2', '3']
More information about the Python-list