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.
89
89
#### ` match `
90
90
91
91
``` purescript
92
- match :: Regex -> String -> Maybe [String]
92
+ match :: Regex -> String -> Maybe [Maybe String]
93
93
```
94
94
95
95
Matches 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.
97
98
See [ reference] ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match ) .
98
99
99
100
#### ` replace `
Original file line number Diff line number Diff line change @@ -121,14 +121,23 @@ foreign import _match
121
121
" " "
122
122
function _match(r, s, Just, Nothing) {
123
123
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
+ }
125
133
}
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 ))
127
135
128
136
-- | 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.
130
139
-- | 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 ]
132
141
match r s = runFn4 _match r s Just Nothing
133
142
134
143
-- | Replaces occurences of the `Regex` with the first string. The replacement
You can’t perform that action at this time.
0 commit comments