diff options
Diffstat (limited to 'src/gleam_stdlib.mjs')
-rw-r--r-- | src/gleam_stdlib.mjs | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/gleam_stdlib.mjs b/src/gleam_stdlib.mjs index 37c3ea2..632c668 100644 --- a/src/gleam_stdlib.mjs +++ b/src/gleam_stdlib.mjs @@ -388,8 +388,17 @@ export function compile_regex(pattern, options) { export function regex_scan(regex, string) { let matches = Array.from(string.matchAll(regex)).map((match) => { - let content = match.shift(); - let submatches = match.map((x) => (x ? new Some(x) : new None())); + const content = match[0]; + const submatches = []; + for (let n = match.length - 1; n > 0; n--) { + if (match[n]) { + submatches[n-1] = new Some(match[n]) + continue + } + if(submatches.length > 0) { + submatches[n-1] = new None() + } + } return new RegexMatch(content, List.fromArray(submatches)); }); return List.fromArray(matches); |