diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/gleam/regex.gleam | 10 | ||||
-rw-r--r-- | src/gleam_stdlib.erl | 10 |
2 files changed, 4 insertions, 16 deletions
diff --git a/src/gleam/regex.gleam b/src/gleam/regex.gleam index dc2a3f8..6534095 100644 --- a/src/gleam/regex.gleam +++ b/src/gleam/regex.gleam @@ -11,16 +11,10 @@ pub external type Regex /// /// - match — the full string of the match. /// - index — the index of the match in the original string. -/// - number — each match is numbered, starting from 1 /// - submatches — a Regex can have subpatterns, sup-parts that are in parentheses. /// pub type Match { - Match( - match: String, - index: Int, - number: Int, - submatches: List(Option(String)), - ) + Match(match: String, index: Int, submatches: List(Option(String))) } /// When a regular expression fails to compile: @@ -113,13 +107,11 @@ pub external fn split(Regex, String) -> List(String) = /// Match( /// match: "on a boat", /// index: 5, -/// number: 1, /// submatches: [Some("boat")] /// ), /// Match( /// match: "in a lake", /// index: 15, -/// number: 2, /// submatches: [Some("lake")] /// ) /// ] diff --git a/src/gleam_stdlib.erl b/src/gleam_stdlib.erl index 217d4d1..85855d1 100644 --- a/src/gleam_stdlib.erl +++ b/src/gleam_stdlib.erl @@ -200,17 +200,13 @@ regex_submatches(String, {S, L}) -> false -> {some, SubMatch} end. -regex_matches(String, [{S, L} | Submatches], Number) -> - {match, binary:part(String, S, L), S, Number, +regex_matches(String, [{S, L} | Submatches]) -> + {match, binary:part(String, S, L), S, lists:map(fun(X) -> regex_submatches(String, X) end, Submatches)}. -regex_captured(_, [], _) -> []; -regex_captured(String, [ H | T ], Number) -> - [ regex_matches(String, H, Number) | regex_captured(String, T, Number + 1) ]. - regex_scan(Regex, String) -> case re:run(String, Regex, [global]) of - {match, Captured} -> regex_captured(String, Captured, 1); + {match, Captured} -> lists:map(fun(X) -> regex_matches(String, X) end, Captured); _ -> [] end. |