Skip to content

Commit 9de0c0f

Browse files
committed
ignore object containing named captured groups, if present
1 parent 9e64410 commit 9de0c0f

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/Data/String/Regex.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,9 @@ exports._replaceBy = function (just) {
7474
return function (s) {
7575
return s.replace(r, function (match) {
7676
var groups = [];
77-
for (var i = 1; i < arguments.length - 2; i++) {
78-
groups.push(arguments[i] == null ? nothing : just(arguments[i]));
77+
var group, i = 1;
78+
while (typeof (group = arguments[i++]) !== 'number') {
79+
groups.push(group == null ? nothing : just(group));
7980
}
8081
return f(match)(groups);
8182
});

test/Test/Data/String/Regex.purs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ testStringRegex = do
3737
assert $ replace' (unsafeRegex "(foo)(bar)?" noFlags) (\s xs -> show xs) "<>" == "<>"
3838
assert $ replace' (unsafeRegex "(foo)(bar)?" noFlags) (\s xs -> show xs) "<foo>" == "<[(Just \"foo\"),Nothing]>"
3939
assert $ replace' (unsafeRegex "(foo)(bar)?" noFlags) (\s xs -> show xs) "<foobar>" == "<[(Just \"foo\"),(Just \"bar\")]>"
40+
assert $ replace' (unsafeRegex "@(?<username>\\w+)" noFlags) (\s xs -> show xs) "@purescript" == "[(Just \"purescript\")]"
4041

4142
log "search"
4243
assert $ search (unsafeRegex "b" noFlags) "abc" == Just 1

0 commit comments

Comments
 (0)