You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: concepts/regular-expressions/about.md
+18-19Lines changed: 18 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,42 +2,41 @@
2
2
3
3
Regular expressions in Gleam follow the **PCRE** specification (**P**erl **C**ompatible **R**egular **E**xpressions), similarly to other popular languages like Java, JavaScript, or Ruby.
4
4
5
-
The `gleam/regex` module offers functions for working with regular expressions.
5
+
The `gleam/regexp` module offers functions for working with regular expressions.
6
6
7
-
~~~~exercism/note
7
+
```exercism/note
8
8
This exercise assumes that you already know regular expression syntax, including character classes, quantifiers, groups, and captures.
9
9
10
-
if you need to refresh your regular expression knowledge, check out one of those sources: [Regular-Expressions.info](https://www.regular-expressions.info), [Rex Egg](https://www.rexegg.com/), [RegexOne](https://regexone.com/), [Regular Expressions 101](https://regex101.com/), [RegExr](https://regexr.com/).
11
-
~~~~
10
+
if you need to refresh your regular expression knowledge, check out one of those sources: [Regular-Expressions.info](https://www.regular-expressions.info), [Rex Egg](https://www.rexegg.com/), [regexOne](https://regexone.com/), [Regular Expressions 101](https://regex101.com/), [regexr](https://regexr.com/).
11
+
```
12
12
13
-
The most common way to create regular expressions is using the `regex.from_string` function.
13
+
The most common way to create regular expressions is using the `regexp.from_string` function.
14
14
15
15
```gleam
16
-
let assert Ok(re) = regex.from_string("test")
16
+
let assert Ok(re) = regexp.from_string("test")
17
17
```
18
18
19
-
The `regex.from_string` function yields an `Error` if the regular expression syntax is invalid, so a let-assertion has been used here to ensure the regular expression is valid.
19
+
The `regexp.from_string` function yields an `Error` if the regular expression syntax is invalid, so a let-assertion has been used here to ensure the regular expression is valid.
20
20
21
-
The `regex.check` function can be used to check if a regular expression matches a string.
21
+
The `regexp.check` function can be used to check if a regular expression matches a string.
22
22
23
23
```gleam
24
-
let assert Ok(re) = regex.from_string("test")
24
+
let assert Ok(re) = regexp.from_string("test")
25
25
26
-
regex.check(re, "this is a test")
26
+
regexp.check(re, "this is a test")
27
27
// -> True
28
28
29
-
regex.check(re, "this is too")
29
+
regexp.check(re, "this is too")
30
30
// -> False
31
31
```
32
32
33
-
34
33
## Captures
35
34
36
-
If you wish to capture substrings using a regular expression, the `regex.scan` function can be used to return a list of matches.
35
+
If you wish to capture substrings using a regular expression, the `regexp.scan` function can be used to return a list of matches.
37
36
38
37
```gleam
39
-
let assert Ok(re) = regex.from_string("[oi]n a (\\w+)")
40
-
regex.scan(with: re, content: "I am on a boat in a lake.")
38
+
let assert Ok(re) = regexp.from_string("[oi]n a (\\w+)")
39
+
regexp.scan(with: re, content: "I am on a boat in a lake.")
41
40
// -> [
42
41
// Match(
43
42
// content: "on a boat",
@@ -52,11 +51,11 @@ regex.scan(with: re, content: "I am on a boat in a lake.")
52
51
53
52
## Modifiers
54
53
55
-
The behaviour of a regular expression can be modified by creating it with the `regex.compile` function and passing in options.
54
+
The behaviour of a regular expression can be modified by creating it with the `regexp.compile` function and passing in options.
56
55
57
56
```gleam
58
-
let options = regex.Options(case_insensitive: True, multi_line: False)
59
-
let assert Ok(re) = regex.compile("[A-Z]", with: options)
60
-
regex.check(re, "abc123")
57
+
let options = regexp.Options(case_insensitive: True, multi_line: False)
58
+
let assert Ok(re) = regexp.compile("[A-Z]", with: options)
0 commit comments