File tree Expand file tree Collapse file tree 2 files changed +16
-6
lines changed Expand file tree Collapse file tree 2 files changed +16
-6
lines changed Original file line number Diff line number Diff line change @@ -89,11 +89,12 @@ Returns `true` if the `Regex` matches the string.
8989#### ` match `
9090
9191``` purescript
92- match :: Regex -> String -> Maybe [String]
92+ match :: Regex -> String -> Maybe [Maybe String]
9393```
9494
9595Matches the string against the ` Regex ` and returns an array of matches
96- if there were any.
96+ if there were any. Each match has type ` Maybe String ` , where ` Nothing `
97+ represents an unmatched optional capturing group.
9798See [ reference] ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match ) .
9899
99100#### ` replace `
Original file line number Diff line number Diff line change @@ -121,14 +121,23 @@ foreign import _match
121121 " " "
122122 function _match(r, s, Just, Nothing) {
123123 var m = s.match(r);
124- return m == null ? Nothing : Just(m);
124+ if (m == null) {
125+ return Nothing;
126+ } else {
127+ var list = [];
128+ for (var i = 0; i < m.length; i++) {
129+ list.push(m[i] == null ? Nothing : Just(m[i]));
130+ }
131+ return Just(list);
132+ }
125133 }
126- " " " :: forall r . Fn4 Regex String ([ String ] -> r ) r r
134+ " " " :: Fn4 Regex String (forall r . r -> Maybe r ) ( forall r . Maybe r ) ( Maybe ( Maybe r ))
127135
128136-- | Matches the string against the `Regex` and returns an array of matches
129- -- | if there were any.
137+ -- | if there were any. Each match has type `Maybe String`, where `Nothing`
138+ -- | represents an unmatched optional capturing group.
130139-- | See [reference](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match).
131- match :: Regex -> String -> Maybe [String ]
140+ match :: Regex -> String -> Maybe [Maybe String ]
132141match r s = runFn4 _match r s Just Nothing
133142
134143-- | Replaces occurences of the `Regex` with the first string. The replacement
You can’t perform that action at this time.
0 commit comments