diff --git a/projects/re-flex/src/re_flex/Main.kiss b/projects/re-flex/src/re_flex/Main.kiss index 994c4b21..bb08ff6c 100644 --- a/projects/re-flex/src/re_flex/Main.kiss +++ b/projects/re-flex/src/re_flex/Main.kiss @@ -5,3 +5,6 @@ match "a" right "bc")) (otherwise (throw "bad match result")))) + +(let [matches (R.distinctMatches "a" "abababab")] + (assert (= 4 matches.length))) \ No newline at end of file diff --git a/projects/re-flex/src/re_flex/R.kiss b/projects/re-flex/src/re_flex/R.kiss index 4147a318..509fa6b3 100644 --- a/projects/re-flex/src/re_flex/R.kiss +++ b/projects/re-flex/src/re_flex/R.kiss @@ -70,4 +70,13 @@ right (r.matchedRight) group - ->idx (r.matched idx)))))) \ No newline at end of file + ->idx (r.matched idx)))))) + +// Return an array of all non-overlapping matches in the given text, from left-to-right +(function :Array distinctMatches [:String regex :String textToSearch &opt :String flags] + (let [matches [] + &mut nextMatch null] + (while (set nextMatch (match regex textToSearch flags)) + (matches.push nextMatch) + (set textToSearch nextMatch.right)) + matches)) \ No newline at end of file