New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
^$ won't split on empty line #39646
Comments
Python 2.3.2 (#49, Oct 2 2003, 20:02:00) [MSC v.1200 >>> import re
>>> re.compile('^$', re.MULTILINE).split('foo\n\nbar')
['foo\n\nbar'] I expect ['foo\n', '\nbar'], since, according to the Thanks, Jan |
Logged In: YES Confirmed on Pythons 2.1.3, 2.2.3, 2.3.2, and current CVS. More generally, split() doesn't appear to split on any empty >>> pat = re.compile(r'\b')
>>> pat.split('(a b)')
['(a b)']
>>> pat.findall('(a b)') # but the pattern matches 4 places
['', '', '', '']
>>> That's probably a design constraint, but isn't documented. ['', 'a', 'b', 'c', ''] back instead of (as they do get) ['abc'] |
Logged In: YES Split never splits on empty substrings; see Tim's answer for a Fred, can you perhaps add something to the documentation? |
Logged In: YES Hi, I was going to file this bug just now myself, as this To answer tim_one's challenge, yes, I *do* expect splitting The fix should be near this line in _sre.c, I think. if (state.start == state.ptr) { I could work on a patch if you'll take it... Mike |
Logged In: YES Since I really needed the functionality described above, I >>> import re
>>> re.sub('(?im)^$', '\f', 'foo\n\nbar').split('\f')
['foo\n', '\nbar'] Another "magic" byte could replace '\f'... Regards, Jan |
Logged In: YES I made a patch that addresses this (bpo-988761). |
Doc note checked in as r57878. Can we conclude based upon Tim's |
Well, I think we can conclude that it's expected by *them*. :-) I If you look at the comments attached to the patch for this bug, it http://bugs.python.org/issue988761 One comment about the your doc fix: You highlight a fairly useless Thanks for working on this! |
I'd feel better about this bug being 'wont fix'ed if I had a sense that |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: