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
re.split doesn't split with zero-width regex #47512
Comments
re.split doesn't split a string when the regex matches a zero characters. For example: re.split(r'\b', 'a b') returns ['a b'] instead of ['', 'a', ' ', 'b', '']. re.split(r'(?<!\w)(?=\w)', 'a b') returns ['a b'] instead of ['', 'a ', |
The attached patch appears to work. |
Probably by design. There's probably even a unittest for this behavior. |
I've found that this issue has been discussed before: bpo-988761. |
New patch version after studying bpo-988761 and doing more testing. |
I don't want to discourage you, but bpo-852532, which is essentially the |
There appear to be 2 opinions on this issue:
Looking at the code, I think it's a bug. Expected behaviour: if 'pattern' is a non-capturing regex, then |
I think it's probably both. The original design was incorrect, though |
I think it's better to leave this alone. Such a subtle change is likely |
Okay. For what it's worth, note that my original 2004 patch for this |
I wonder whether it could be put into Python 3 where certain breaks in |
I think Mike Coleman proposal of enabling this behaviour via flag is I would like to add this patch as a new item to the general Regexp |
The problem with doing this per 3.0 is that it's impossible to write a I'm okay with adding a flag to enable this behavior though. Please open |
Sorry to revive this dormant (?) topic - has anybody brought this any further? This "feature" has tripped me up a few times, and I would be all for adding a flag to enable the "split on zero-size matches" behavior, but I myself am not competent enough to code a patch. |
You could try the regex module mentioned in bpo-2636. |
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: