Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Next version

- Add `RegExp.setLastIndex` function. https://github.com/rescript-association/rescript-core/pull/219
- Add `Nullable.isNullable` function. https://github.com/rescript-association/rescript-core/pull/227
- Remove some deps to Belt, Pervasives and Js. https://github.com/rescript-association/rescript-core/pull/226/commits

Expand Down
1 change: 1 addition & 0 deletions src/Core__RegExp.res
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module Result = {
@return(nullable) @send external exec: (t, string) => option<Result.t> = "exec"

@get external lastIndex: t => int = "lastIndex"
@set external setLastIndex: (t, int) => unit = "lastIndex"
@get external ignoreCase: t => bool = "ignoreCase"
@get external global: t => bool = "global"
@get external multiline: t => bool = "multiline"
Expand Down
20 changes: 20 additions & 0 deletions src/Core__RegExp.resi
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,26 @@ Console.log(regexp->RegExp.lastIndex) // Logs `4` to the console
@get
external lastIndex: t => int = "lastIndex"

/**
`setLastIndex(regexp, index)` set the index the next match will start from.

See [`RegExp.lastIndex`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastIndex) on MDN.

## Examples
```rescript
// Match the first word in a sentence
let regexp = RegExp.fromString("\\w+")
let someStr = "Many words here."

regexp->RegExp.setLastIndex(4)
regexp->RegExp.exec(someStr)->ignore

Console.log(regexp->RegExp.lastIndex) // Logs `10` to the console
```
*/
@set
external setLastIndex: (t, int) => unit = "lastIndex"

/**
`ignoreCase(regexp)` returns whether the ignore case (`i`) flag is set on this `RegExp`.

Expand Down