Skip to content

Commit 1f0d70d

Browse files
mediremicknitt
authored andcommitted
Add optional flags argument to RegExp.fromString
1 parent 0feb8a3 commit 1f0d70d

File tree

4 files changed

+13
-3
lines changed

4 files changed

+13
-3
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
- Fix node.js ExperimentalWarning. https://github.com/rescript-lang/rescript/pull/7379
1818
- Fix issue with gentype and stdlib json. https://github.com/rescript-lang/rescript/pull/7378
1919
- Fix type of `RegExp.Result.matches`. https://github.com/rescript-lang/rescript/pull/7393
20+
- Add optional `flags` argument to `RegExp.fromString` and deprecate `RegExp.fromStringWithFlags`. https://github.com/rescript-lang/rescript/pull/7393
2021

2122
#### :house: Internal
2223

runtime/Stdlib_RegExp.res

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module Result = {
88
@get external input: t => string = "input"
99
}
1010

11-
@new external fromString: string => t = "RegExp"
11+
@new external fromString: (string, ~flags: string=?) => t = "RegExp"
1212
@new external fromStringWithFlags: (string, ~flags: string) => t = "RegExp"
1313

1414
@send external test: (t, string) => bool = "test"

runtime/Stdlib_RegExp.resi

+10-1
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,18 @@ switch regexp->RegExp.exec("ReScript is pretty cool, right?") {
8787
| None => Console.log("Nope, no match...")
8888
| Some(result) => Console.log(result->RegExp.Result.fullMatch) // Prints "ReScript"
8989
}
90+
91+
// Match 'foo' with case insensitive flag
92+
let regexp = RegExp.fromString("foo", ~flags="i")
93+
94+
switch regexp->RegExp.exec("FOO") {
95+
| None => Console.log("Nope, no match...")
96+
| Some(result) => Console.log(result->RegExp.Result.fullMatch) // Prints "FOO"
97+
}
9098
```
9199
*/
92100
@new
93-
external fromString: string => t = "RegExp"
101+
external fromString: (string, ~flags: string=?) => t = "RegExp"
94102

95103
/**
96104
`fromStringWithFlags(string)` creates a `RegExp.t` from the provided string, using the provided `flags`. This can then be used to match on strings using `RegExp.exec`.
@@ -108,6 +116,7 @@ switch regexp->RegExp.exec("ReScript is pretty cool, right?") {
108116
}
109117
```
110118
*/
119+
@deprecated("Use `fromString` instead")
111120
@new
112121
external fromStringWithFlags: (string, ~flags: string) => t = "RegExp"
113122

tests/analysis_tests/tests/src/expected/CompletionExpressions.res.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1384,7 +1384,7 @@ Path mkStuff
13841384
"label": "RegExp.fromString()",
13851385
"kind": 12,
13861386
"tags": [],
1387-
"detail": "string => t",
1387+
"detail": "(string, ~flags: string=?) => t",
13881388
"documentation": null,
13891389
"insertText": "RegExp.fromString($0)",
13901390
"insertTextFormat": 2

0 commit comments

Comments
 (0)