O'Reilly logo

Elixir Cookbook by Paulo A Pereira

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using regular expressions

Elixir supports regular expressions via Erlang's re module. This is one of those situations that we mentioned in the Using Erlang from Elixir recipe in Chapter 1, Command Line. However, we don't have to use the re Erlang module directly! We have the Elixir Regex module that is built on top of the Erlang module and is also based on Perl Compatible Regular Expressions (PCRE).

In this recipe, we use the ~r sigil to define regular expressions and operate on strings.

Note

The ~r sigil is a special form that allows for the creation of regular expressions as alternatives to the Regex.compile!/2 function.

Internally, a regular expression is represented by the Regex struct (%Regex{}).

Getting ready

Start a new IEx session by entering ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required