Skip to content

Commit 27256dc

Browse files
authored
Document native regex syntax (#1019)
* document native regex syntax * update more docs
1 parent 79d63a5 commit 27256dc

File tree

3 files changed

+36
-3
lines changed

3 files changed

+36
-3
lines changed

misc_docs/syntax/extension_regular_expression.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ summary: "This is the `regular expression` extension point."
66
category: "extensionpoints"
77
---
88

9+
> Deprecated in favor of native regular expression syntax in v12+
10+
911
`%re` is used to create JavaScript regular expressions.
1012

1113
<CodeTab labels={["ReScript", "JS Output"]}>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
id: "regular-expression-syntax"
3+
keywords: ["regular", "expression", "regex"]
4+
name: "/re/"
5+
summary: "This is the `regular expression` syntax."
6+
category: "languageconstructs"
7+
---
8+
9+
> Available in v12+
10+
11+
You write regular expressions in ReScript just like you do in JavaScript.
12+
13+
<CodeTab labels={["ReScript", "JS Output"]}>
14+
15+
```res
16+
let regex = /^hello/
17+
let result = regex->RegExp.test("hello world")
18+
```
19+
20+
```js
21+
let regex = /^hello/;
22+
23+
let result = regex.test("hello world");
24+
```
25+
26+
</CodeTab>
27+
28+
### References
29+
30+
* [Regular Expressions](/docs/manual/latest/primitive-types#regular-expression)
31+
* [RegExp API](/docs/manual/latest/api/core/regexp)

pages/docs/manual/v12.0.0/primitive-types.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,15 @@ ReScript regular expressions compile cleanly to their JavaScript counterpart:
112112
<CodeTab labels={["ReScript", "JS Output"]}>
113113

114114
```res example
115-
let r = %re("/b/g")
115+
let r = /b/g
116116
```
117117
```js
118-
var r = /b/g;
118+
let r = /b/g;
119119
```
120120

121121
</CodeTab>
122122

123-
A regular expression like the above has the type `Re.t`. The [RegExp](api/core/regexp) module contains the regular expression helpers you have seen in JS.
123+
A regular expression like the above has the type `RegExp.t`. The [RegExp](api/core/regexp) module contains the regular expression helpers you have seen in JS.
124124

125125
## Boolean
126126

0 commit comments

Comments
 (0)