Elixir’s regex is based on PCRE (Perl Compatible Regular Expressions).
The Regex
module gives us the following methods:
run
scan
split
replace
run
runs the regular expression against the given string until the first match.
You can use the
~r{<regex>}
sigil or~r/<regex>/
. Using the curly brackets version is more convenient as you can match/
forward slash characters without having to escape it.
scan
performs run
several times collecting all matches of the regular expression.
split
splits the given target based on the given pattern.
replace
takes in a regex, a string and a replacement, returns a new string where all matches are replaced by the replacement.
Additional reading: