Skip to content

Commit 69a3237

Browse files
committed
refactor(others/js): use regex literals
1 parent 0c08bfa commit 69a3237

File tree

3 files changed

+29
-29
lines changed

3 files changed

+29
-29
lines changed

jscomp/others/js_re.res

+3-3
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ external input: result => string = "input"
5555

5656
/**
5757
Constructs a RegExp object (Js.Re.t) from a `string`.
58-
Regex literals `%re("/.../")` should generally be preferred, but `fromString`
58+
Regex literals `/.../` should generally be preferred, but `fromString`
5959
is useful when you need to dynamically construct a regex using strings,
6060
exactly like when you do so in JavaScript.
6161
@@ -112,7 +112,7 @@ set.
112112
## Examples
113113
114114
```rescript
115-
let re = %re("/ab*TODO/g")
115+
let re = /ab*TODO/g
116116
let str = "abbcdefabh"
117117
118118
let break = ref(false)
@@ -166,7 +166,7 @@ Returns `Some(Js.Re.result)` if a match is found, `None` otherwise.
166166
* Ignore case
167167
*/
168168
169-
let re = %re("/quick\s(brown).+?(jumps)/ig")
169+
let re = /quick\s(brown).+?(jumps)/ig
170170
let result = Js.Re.exec_(re, "The Quick Brown Fox Jumps Over The Lazy Dog")
171171
```
172172

jscomp/others/js_string.res

+11-11
Original file line numberDiff line numberDiff line change
@@ -428,11 +428,11 @@ on MDN.
428428
## Examples
429429
430430
```rescript
431-
Js.String.match_(%re("/b[aeiou]t/"), "The better bats") == Some(["bet"])
432-
Js.String.match_(%re("/b[aeiou]t/g"), "The better bats") == Some(["bet", "bat"])
433-
Js.String.match_(%re("/(\d+)-(\d+)-(\d+)/"), "Today is 2018-04-05.") ==
431+
Js.String.match_(/b[aeiou]t/, "The better bats") == Some(["bet"])
432+
Js.String.match_(/b[aeiou]t/g, "The better bats") == Some(["bet", "bat"])
433+
Js.String.match_(/(\d+)-(\d+)-(\d+)/, "Today is 2018-04-05.") ==
434434
Some(["2018-04-05", "2018", "04", "05"])
435-
Js.String.match_(%re("/b[aeiou]g/"), "The large container.") == None
435+
Js.String.match_(/b[aeiou]g/, "The large container.") == None
436436
```
437437
*/
438438
external match_: Js_re.t => option<array<option<t>>> = "match"
@@ -514,8 +514,8 @@ on MDN.
514514
## Examples
515515
516516
```rescript
517-
Js.String.replaceByRe(%re("/[aeiou]/g"), "x", "vowels be gone") == "vxwxls bx gxnx"
518-
Js.String.replaceByRe(%re("/(\w+) (\w+)/"), "$2, $1", "Juan Fulano") == "Fulano, Juan"
517+
Js.String.replaceByRe(/[aeiou]/g, "x", "vowels be gone") == "vxwxls bx gxnx"
518+
Js.String.replaceByRe(/(\w+) (\w+)/, "$2, $1", "Juan Fulano") == "Fulano, Juan"
519519
```
520520
*/
521521
external replaceByRe: (Js_re.t, t) => t = "replace"
@@ -534,7 +534,7 @@ on MDN.
534534
535535
```rescript
536536
let str = "beautiful vowels"
537-
let re = %re("/[aeiou]/g")
537+
let re = /[aeiou]/g
538538
let matchFn = (matchPart, _offset, _wholeString) => Js.String.toUpperCase(matchPart)
539539
540540
Js.String.unsafeReplaceBy0(re, matchFn, str) == "bEAUtIfUl vOwEls"
@@ -557,7 +557,7 @@ on MDN.
557557
558558
```rescript
559559
let str = "Jony is 40"
560-
let re = %re("/(Jony is )\d+/g")
560+
let re = /(Jony is )\d+/g
561561
let matchFn = (_match, part1, _offset, _wholeString) => {
562562
part1 ++ "41"
563563
}
@@ -582,7 +582,7 @@ on MDN.
582582
583583
```rescript
584584
let str = "7 times 6"
585-
let re = %re("/(\d+) times (\d+)/")
585+
let re = /(\d+) times (\d+)/
586586
let matchFn = (_match, p1, p2, _offset, _wholeString) => {
587587
switch (Belt.Int.fromString(p1), Belt.Int.fromString(p2)) {
588588
| (Some(x), Some(y)) => Belt.Int.toString(x * y)
@@ -619,8 +619,8 @@ on MDN.
619619
## Examples
620620
621621
```rescript
622-
Js.String.search(%re("/\d+/"), "testing 1 2 3") == 8
623-
Js.String.search(%re("/\d+/"), "no numbers") == -1
622+
Js.String.search(/\d+/, "testing 1 2 3") == 8
623+
Js.String.search(/\d+/, "no numbers") == -1
624624
```
625625
*/
626626
external search: Js_re.t => int = "search"

jscomp/others/js_string2.res

+15-15
Original file line numberDiff line numberDiff line change
@@ -432,11 +432,11 @@ on MDN.
432432
## Examples
433433
434434
```rescript
435-
Js.String2.match_("The better bats", %re("/b[aeiou]t/")) == Some(["bet"])
436-
Js.String2.match_("The better bats", %re("/b[aeiou]t/g")) == Some(["bet", "bat"])
437-
Js.String2.match_("Today is 2018-04-05.", %re("/(\d+)-(\d+)-(\d+)/")) ==
435+
Js.String2.match_("The better bats", /b[aeiou]t/) == Some(["bet"])
436+
Js.String2.match_("The better bats", /b[aeiou]t/g) == Some(["bet", "bat"])
437+
Js.String2.match_("Today is 2018-04-05.", /(\d+)-(\d+)-(\d+)/) ==
438438
Some(["2018-04-05", "2018", "04", "05"])
439-
Js.String2.match_("The large container.", %re("/b[aeiou]g/")) == None
439+
Js.String2.match_("The large container.", /b[aeiou]g/) == None
440440
```
441441
*/
442442
external match_: (t, Js_re.t) => option<array<option<t>>> = "match"
@@ -516,8 +516,8 @@ on MDN.
516516
## Examples
517517
518518
```rescript
519-
Js.String2.replaceByRe("vowels be gone", %re("/[aeiou]/g"), "x") == "vxwxls bx gxnx"
520-
Js.String2.replaceByRe("Juan Fulano", %re("/(\w+) (\w+)/"), "$2, $1") == "Fulano, Juan"
519+
Js.String2.replaceByRe("vowels be gone", /[aeiou]/g, "x") == "vxwxls bx gxnx"
520+
Js.String2.replaceByRe("Juan Fulano", /(\w+) (\w+)/, "$2, $1") == "Fulano, Juan"
521521
```
522522
*/
523523
external replaceByRe: (t, Js_re.t, t) => t = "replace"
@@ -536,7 +536,7 @@ on MDN.
536536
537537
```rescript
538538
let str = "beautiful vowels"
539-
let re = %re("/[aeiou]/g")
539+
let re = /[aeiou]/g
540540
let matchFn = (matchPart, _offset, _wholeString) => Js.String2.toUpperCase(matchPart)
541541
542542
Js.String2.unsafeReplaceBy0(str, re, matchFn) == "bEAUtIfUl vOwEls"
@@ -559,7 +559,7 @@ on MDN.
559559
560560
```rescript
561561
let str = "Jony is 40"
562-
let re = %re("/(Jony is )\d+/g")
562+
let re = /(Jony is )\d+/g
563563
let matchFn = (_match, part1, _offset, _wholeString) => {
564564
part1 ++ "41"
565565
}
@@ -584,7 +584,7 @@ on MDN.
584584
585585
```rescript
586586
let str = "7 times 6"
587-
let re = %re("/(\d+) times (\d+)/")
587+
let re = /(\d+) times (\d+)/
588588
let matchFn = (_match, p1, p2, _offset, _wholeString) => {
589589
switch (Belt.Int.fromString(p1), Belt.Int.fromString(p2)) {
590590
| (Some(x), Some(y)) => Belt.Int.toString(x * y)
@@ -621,8 +621,8 @@ on MDN.
621621
## Examples
622622
623623
```rescript
624-
Js.String2.search("testing 1 2 3", %re("/\d+/")) == 8
625-
Js.String2.search("no numbers", %re("/\d+/")) == -1
624+
Js.String2.search("testing 1 2 3", /\d+/) == 8
625+
Js.String2.search("no numbers", /\d+/) == -1
626626
```
627627
*/
628628
external search: (t, Js_re.t) => int = "search"
@@ -709,7 +709,7 @@ on MDN.
709709
## Examples
710710
711711
```rescript
712-
Js.String2.splitByRe("art; bed , cog ;dad", %re("/\s*[,;]\s*TODO/")) == [
712+
Js.String2.splitByRe("art; bed , cog ;dad", /\s*[,;]\s*TODO/) == [
713713
Some("art"),
714714
Some("bed"),
715715
Some("cog"),
@@ -732,15 +732,15 @@ on MDN.
732732
## Examples
733733
734734
```rescript
735-
Js.String2.splitByReAtMost("one: two: three: four", %re("/\s*:\s*TODO/"), ~limit=3) == [
735+
Js.String2.splitByReAtMost("one: two: three: four", /\s*:\s*TODO/, ~limit=3) == [
736736
Some("one"),
737737
Some("two"),
738738
Some("three"),
739739
]
740740
741-
Js.String2.splitByReAtMost("one: two: three: four", %re("/\s*:\s*TODO/"), ~limit=0) == []
741+
Js.String2.splitByReAtMost("one: two: three: four", /\s*:\s*TODO/, ~limit=0) == []
742742
743-
Js.String2.splitByReAtMost("one: two: three: four", %re("/\s*:\s*TODO/"), ~limit=8) == [
743+
Js.String2.splitByReAtMost("one: two: three: four", /\s*:\s*TODO/, ~limit=8) == [
744744
Some("one"),
745745
Some("two"),
746746
Some("three"),

0 commit comments

Comments
 (0)