File tree 3 files changed +22
-0
lines changed
3 files changed +22
-0
lines changed Original file line number Diff line number Diff line change 2
2
3
3
## Next version
4
4
5
+ - Add ` RegExp.setLastIndex ` function. https://github.com/rescript-association/rescript-core/pull/219
5
6
- Add ` Nullable.isNullable ` function. https://github.com/rescript-association/rescript-core/pull/227
6
7
- Remove some deps to Belt, Pervasives and Js. https://github.com/rescript-association/rescript-core/pull/226/commits
7
8
Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ module Result = {
15
15
@return (nullable ) @send external exec : (t , string ) => option <Result .t > = "exec"
16
16
17
17
@get external lastIndex : t => int = "lastIndex"
18
+ @set external setLastIndex : (t , int ) => unit = "lastIndex"
18
19
@get external ignoreCase : t => bool = "ignoreCase"
19
20
@get external global : t => bool = "global"
20
21
@get external multiline : t => bool = "multiline"
Original file line number Diff line number Diff line change @@ -170,6 +170,26 @@ Console.log(regexp->RegExp.lastIndex) // Logs `4` to the console
170
170
@get
171
171
external lastIndex: t => int = "lastIndex"
172
172
173
+ /**
174
+ `setLastIndex(regexp, index)` set the index the next match will start from.
175
+
176
+ See [`RegExp.lastIndex`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastIndex) on MDN.
177
+
178
+ ## Examples
179
+ ```rescript
180
+ // Match the first word in a sentence
181
+ let regexp = RegExp.fromString("\\w+")
182
+ let someStr = "Many words here."
183
+
184
+ regexp->RegExp.setLastIndex(4)
185
+ regexp->RegExp.exec(someStr)->ignore
186
+
187
+ Console.log(regexp->RegExp.lastIndex) // Logs `10` to the console
188
+ ```
189
+ */
190
+ @set
191
+ external setLastIndex: (t, int) => unit = "lastIndex"
192
+
173
193
/**
174
194
`ignoreCase(regexp)` returns whether the ignore case (`i`) flag is set on this `RegExp`.
175
195
You can’t perform that action at this time.
0 commit comments