Skip to content

Document native regex syntax #1019

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 4, 2025
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
2 changes: 2 additions & 0 deletions misc_docs/syntax/extension_regular_expression.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ summary: "This is the `regular expression` extension point."
category: "extensionpoints"
---

> Deprecated in favor of native regular expression syntax in v12+

`%re` is used to create JavaScript regular expressions.

<CodeTab labels={["ReScript", "JS Output"]}>
Expand Down
31 changes: 31 additions & 0 deletions misc_docs/syntax/language_regular_expression.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
id: "regular-expression-syntax"
keywords: ["regular", "expression", "regex"]
name: "/re/"
summary: "This is the `regular expression` syntax."
category: "languageconstructs"
---

> Available in v12+

You write regular expressions in ReScript just like you do in JavaScript.

<CodeTab labels={["ReScript", "JS Output"]}>

```res
let regex = /^hello/
let result = regex->RegExp.test("hello world")
```

```js
let regex = /^hello/;

let result = regex.test("hello world");
```

</CodeTab>

### References

* [Regular Expressions](/docs/manual/latest/primitive-types#regular-expression)
* [RegExp API](/docs/manual/latest/api/core/regexp)
6 changes: 3 additions & 3 deletions pages/docs/manual/v12.0.0/primitive-types.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,15 @@ ReScript regular expressions compile cleanly to their JavaScript counterpart:
<CodeTab labels={["ReScript", "JS Output"]}>

```res example
let r = %re("/b/g")
let r = /b/g
```
```js
var r = /b/g;
let r = /b/g;
```

</CodeTab>

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.
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.

## Boolean

Expand Down