# Regex

Regex is based on PCRE (Perl Compatible Regular Expressions) and built on top of Erlang's `:re` module. More information can be found in the [`:re` module documentation](http://www.erlang.org/doc/man/re.html).

```elixir
# A simple regular expression that matches foo anywhere in the string
~r/foo/

# A regular expression with case insensitive and Unicode options
~r/foo/iu

#Internally a struct so matches
~r/(?<foo>.)(?<bar>.)/ == ~r/(?<foo>.)(?<bar>.)/


~r/https?.*example\d?\.com$/
~r/https?.*eta-pr-[[:digit:]]+.onrender.com$/ #matches "https://eta-pr-455.onrender.com" where number can change
```

## Usage

```elixir
String.match?("123", ~r/^[[:alnum:]]+$/) #true
String.match?("123 456", ~r/^[[:alnum:][:blank:]]+$/) #true
```

The supported class names are:

* alnum - Letters and digits
* alpha - Letters
* ascii - Character codes 0-127
* blank - Space or tab only
* cntrl - Control characters
* digit - Decimal digits (same as \d)
* graph - Printing characters, excluding space
* lower - Lowercase letters
* print - Printing characters, including space
* punct - Printing characters, excluding letters, digits, and space
* space - Whitespace (the same as \s from PCRE 8.34)
* upper - Uppercase letters
* word - "Word" characters (same as \w)
* xdigit - Hexadecimal digits


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://openai.gitbook.io/code-cheatsheets/all/elixir/regex.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
