A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-list/2005-September/333702.html below:

Regular Expression IGNORECASE different for findall and split?

Regular Expression IGNORECASE different for findall and split?Peter Otten __peter__ at web.de
Tue Sep 6 16:13:30 EDT 2005
Chris wrote:

>  >>> 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(re.split)
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

>>> re.I
2

Use re.compile() to get the desired behaviour:

>>> re.compile("x", re.I).split("1x2X3")
['1', '2', '3']

Peter

More information about the Python-list mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4