Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upRegex.split with submatches #803
Comments
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment
Hide comment
process-bot
Jan 6, 2017
Thanks for the issue! Make sure it satisfies this checklist. My human colleagues will appreciate it!
Here is what to expect next, and if anyone wants to comment, keep these things in mind.
process-bot
commented
Jan 6, 2017
|
Thanks for the issue! Make sure it satisfies this checklist. My human colleagues will appreciate it! Here is what to expect next, and if anyone wants to comment, keep these things in mind. |
evancz
closed this
in
elm/regex@8ad4a15
Mar 25, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
spikefoo commentedJan 6, 2017
(Regex meta issue: #722)
What is the intended behavior of
Regex.splitwhen using a seperator regex with subpatterns?Regex with no subpatterns
If you use
Regex.splitwith a seperator regex that has no subpatterns, the result does not include the seperators. E.g.:The implementation of
Regex.splituses JavascriptString#split:Regex with subpatterns
The documentation for
Regex.splitdoesn't specify the intended behavior for a regex with subpatterns (and there are no tests for this case), but it's still implemented using JavascriptString#split. This means that subpatterns are included in the resulting array:This is a nice feature to have, and the docs and tests can be updated to support it. But it breaks when using optional subpatterns:
Regex with optional subpatterns
Using optional subpatterns in Javascript can cause the result to have
undefinedelements:This breaks Elm:
It could be fixed by returning
List (Maybe String)instead ofList String, but that would complicate the use ofRegex.splitin the common case where subpatterns aren't used.Ideally, it should be easy to use
Regex.splitin the first case (no subpatterns) and preferably the second case too (no optional subpatterns), while keepingRegex.splitsafe.