File tree Expand file tree Collapse file tree 2 files changed +21
-0
lines changed
Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ module Result = {
1515@return (nullable ) @send external exec : (t , string ) => option <Result .t > = "exec"
1616
1717@get external lastIndex : t => int = "lastIndex"
18+ @set external setLastIndex : (t , int ) => unit = "lastIndex"
1819@get external ignoreCase : t => bool = "ignoreCase"
1920@get external global : t => bool = "global"
2021@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
170170@get
171171external lastIndex : t => int = "lastIndex"
172172
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+
173193/**
174194`ignoreCase(regexp)` returns whether the ignore case (`i`) flag is set on this `RegExp`.
175195
You can’t perform that action at this time.
0 commit comments