Unicode.Regex.compile
You're seeing just the function
compile
, go back to Unicode.Regex module for more information.
Compiles a binary regular expression after expanding any Unicode Sets.
Arguments
string
is a regular expression in string formoptions
is a string or a list which is passed unchanged toRegex.compile/2
. The default is "u" meaning the regular expression will operate in Unicode mode
Returns
{:ok, regex}
or{:error, {message, index}}
Notes
This function operates by splitting the string at the boundaries of Unicode Set markers which are:
- Posix style:
[:
and:]
- Perl style:
\p{
and}
This parsing is naive meaning that is does not take any character escaping into account when s plitting the string.
Example
iex> Unicode.Regex.compile("[:Zs:]")
{:ok, ~r/[\x{20}\x{A0}\x{1680}\x{2000}-\x{200A}\x{202F}\x{205F}\x{3000}]/u}
iex> Unicode.Regex.compile("\\p{Zs}")
{:ok, ~r/[\x{20}\x{A0}\x{1680}\x{2000}-\x{200A}\x{202F}\x{205F}\x{3000}]/u}
iex> Unicode.Regex.compile("[:ZZZZ:]")
{:error, {'POSIX named classes are supported only within a class', 0}}