Skip to content

regex -> regexp #557

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
16 changes: 8 additions & 8 deletions exercises/concept/log-parser/.docs/hints.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,26 @@

## 1. Identify garbled log lines

- The [`regex.from_string` function][from-string] can be used to compile a regular expression.
- The [`regex.check` function][check] can be used to test whether a regular expression matches a string.
- The [`regexp.from_string` function][from-string] can be used to compile a regular expression.
- The [`regexp.check` function][check] can be used to test whether a regular expression matches a string.
- Don't forget to escape characters that have special meaning in regular expressions.

## 2. Split the log line

- The [`regex.split` function][split] can be used to split a string using a regular expression.
- The [`regexp.split` function][split] can be used to split a string using a regular expression.
- Don't forget to escape characters that have special meaning in regular expressions.

## 3. Tag lines with user names

- The [`regex.scan` function][scan] can be used used to capture parts of a string using a regular expression.
- The [`regexp.scan` function][scan] can be used used to capture parts of a string using a regular expression.
- Don't forget to escape characters that have special meaning in regular expressions.

[website-regex-info]: https://www.regular-expressions.info
[website-rexegg]: https://www.rexegg.com/
[website-regexone]: https://regexone.com/
[website-regex-101]: https://regex101.com/
[website-regexr]: https://regexr.com/
[from-string]: https://hexdocs.pm/gleam_stdlib/gleam/regex.html#from_string
[check]: https://hexdocs.pm/gleam_stdlib/gleam/regex.html#check
[split]: https://hexdocs.pm/gleam_stdlib/gleam/regex.html#split
[scan]: https://hexdocs.pm/gleam_stdlib/gleam/regex.html#scan
[from-string]: https://hexdocs.pm/gleam_regexp/gleam/rregexp.html#from_string
[check]: https://hexdocs.pm/gleam_regexp/gleam/regexp.html#check
[split]: https://hexdocs.pm/gleam_regexp/gleam/regexp.html#split
[scan]: https://hexdocs.pm/gleam_regexp/gleam/regexp.html#scan
28 changes: 14 additions & 14 deletions exercises/concept/log-parser/.docs/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,42 @@

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.

The `gleam/regex` module offers functions for working with regular expressions.
The `gleam/regexp` module from the `gleam_regexp` package offers functions for working with regular expressions.

~~~~exercism/note
This exercise assumes that you already know regular expression syntax, including character classes, quantifiers, groups, and captures.

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/).
~~~~

The most common way to create regular expressions is using the `regex.from_string` function.
The most common way to create regular expressions is using the `regexp.from_string` function.

```gleam
let assert Ok(re) = regex.from_string("test")
let assert Ok(re) = regexp.from_string("test")
```

The regular expression creation functions return an error if the regular expression syntax is invalid, so a let-assertion has been used here to ensure the regular expression is valid.

The `regex.check` function can be used to check if a regular expression matches a string.
The `regexp.check` function can be used to check if a regular expression matches a string.

```gleam
let assert Ok(re) = regex.from_string("test")
let assert Ok(re) = regexp.from_string("test")

regex.check(re, "this is a test")
regexp.check(re, "this is a test")
// -> True

regex.check(re, "this is too")
regexp.check(re, "this is too")
// -> False
```


### Captures

If you wish to capture substrings using a regular expression the `regex.scan` function can be used to return a list of matches.
If you wish to capture substrings using a regular expression the `regexp.scan` function can be used to return a list of matches.

```gleam
let assert Ok(re) = regex.from_string("[oi]n a (\\w+)")
regex.scan(with: re, content: "I am on a boat in a lake.")
let assert Ok(re) = regexp.from_string("[oi]n a (\\w+)")
regexp.scan(with: re, content: "I am on a boat in a lake.")
// -> [
// Match(
// content: "on a boat",
Expand All @@ -54,11 +54,11 @@ regex.scan(with: re, content: "I am on a boat in a lake.")

### Modifiers

The behaviour of a regular expression can be modified by creating it with the `regex.compile` function and passing in options.
The behaviour of a regular expression can be modified by creating it with the `regexp.compile` function and passing in options.

```gleam
let options = regex.Options(case_insensitive: True, multi_line: False)
let assert Ok(re) = regex.compile("[A-Z]", with: options)
regex.check(re, "abc123")
let options = regexp.Options(case_insensitive: True, multi_line: False)
let assert Ok(re) = regexp.compile("[A-Z]", with: options)
regexp.check(re, "abc123")
// -> True
```
Loading