Bug 1772 – (D1 only) regexp.split behavior with captures needs to be documented
Status
RESOLVED
Resolution
WONTFIX
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D1 (retired)
Platform
All
OS
All
Creation time
2008-01-07T23:03:00Z
Last change time
2015-11-03T17:45:49Z
Assigned to
nobody
Creator
wbaxter
Comments
Comment #0 by wbaxter — 2008-01-07T23:03:31Z
I want to split columns out of a row of numbers. They may be separated by comas or by just white space. So I tried this:
The splitter regexp
auto re_splitter = new RegExp(r"(\s+|\s*,\s*)");
char[][] numbers = re_splitter.split(line);
if input is a line like:
410.90711,352.879
The output from that is the array
[410.90711,,,352.879]
After a bit of debugging, it turns out the problem is the grouping in the regexp.
Removing the parens fixes the problem in this case, but there are cases where you need parens for grouping and not for the capturing side effect. So I think this is a bug. Only match 0 should be considered significant for splitting, not the submatches.
Comment #1 by wbaxter — 2008-01-07T23:04:14Z
fixed summary
Comment #2 by wbaxter — 2008-01-08T14:12:41Z
It seems I've been duped by writefln's output.
Further investigation shows that this:
[410.90711,,,352.879]
is actually this:
["410.90711", ",", "352.879"]
and not a 4-element list with two empty strings as I thought.
I discovered this because I checked what python does with captures, and it is this:
"""
If capturing parentheses are used in pattern, then the text of all groups in the pattern are also returned as part of the resulting list.
"""
So that made me think maybe D could be trying to do something similar.
Apparently it is. So please just document it.
I'm no expert D1 stuff, but I belive issue is still applicable for D1.
Come to think of, I closed few D1 issues like this in the past, maybe we should close this one too (marked as D1 for now).
D1/D2 regexp is broken in many ways and nobody is doing any work on Phobos/D1 to fix it AFIAK, Tango folks have their own regex anyway.
Comment #8 by yebblies — 2012-03-23T07:06:04Z
I guess it can be closed when D1 is discontinued at the end of the year.
Comment #9 by andrei — 2015-11-03T17:45:49Z
It's unlikely this D1 issue will get worked on, if anyone plans to work on it feel free to reopen.