Our first program will demonstrate common regular expression tasks in Elixir. Here’s the full source code:
To run the program, save it as regex_example.exs and use elixir:
In Elixir, regular expressions are represented using the ~r sigil. The Regex module provides functions for working with regular expressions.
Unlike Go, Elixir doesn’t have separate functions for string and binary operations on regular expressions. The same functions work for both.
Elixir’s Regex.run/3 and Regex.scan/3 functions are quite versatile and can be used to achieve the functionality of various Go regex functions by using different options.
For a complete reference on Elixir regular expressions, check the Regex module docs.