Skip to content
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

split should include capture groups in results #7

Open
pythe opened this issue Oct 8, 2018 · 1 comment
Open

split should include capture groups in results #7

pythe opened this issue Oct 8, 2018 · 1 comment

Comments

@pythe
Copy link

pythe commented Oct 8, 2018

As a web developer approaching Elm from Javascript, I expect regexes and associated functions to behave the same as in JS.

Issue: In Elm 0.18 Core/Regex, an expression containing capture groups would splice captures into the returned array. In Elm 0.19 Regex, the capture groups are omitted.

Justification: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split#Description

If separator is a regular expression that contains capturing parentheses, then each time separator is matched, the results (including any undefined results) of the capturing parentheses are spliced into the output array.

Examples:

---- Elm 0.19.0 ----------------------------------------------------------------
Read <https://elm-lang.org/0.19.0/repl> to learn more: exit, help, imports, etc.
--------------------------------------------------------------------------------
> import Regex
> Regex.split (Maybe.withDefault Regex.never <| Regex.fromString ",") "a,b,c,d"
["a","b","c","d"] : List String
> Regex.split (Maybe.withDefault Regex.never <| Regex.fromString "(,)") "a,b,c,d"
["a","b","c","d"] : List String
---- elm-repl 0.18.0 -----------------------------------------------------------
 :help for help, :exit to exit, more at <https://github.com/elm-lang/elm-repl>
--------------------------------------------------------------------------------
> import Regex exposing (regex, HowMany(All))
> Regex.split All (regex ",") "a,b,c,d"
["a","b","c","d"] : List String
> Regex.split All (regex "(,)") "a,b,c,d"
["a",",","b",",","c",",","d"] : List String
// This was run in Chrome 69
console.log("a,b,c,d,e".split(/,/));
console.log("a,b,c,d,e".split(/(,)/));
VM59:1 (5) ["a", "b", "c", "d", "e"]
VM59:2 (9) ["a", ",", "b", ",", "c", ",", "d", ",", "e"]
@pythe
Copy link
Author

pythe commented Oct 8, 2018

I'm willing to try providing a pull request if this issue is valid.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant