In the Using regular expressions recipe, we used a sigil to define a regular expression. A sigil is an alternative way to define structures that have a textual representation within the language.
This recipe will show you the use of the ~W
and ~w
sigils to create word lists.
To define word lists using sigils, perform the following steps:
Define a word list with no interpolation:
iex(1)> ~W(one two "three" ^ @ \| 12345) ["one", "two", "\"three\"", "^", "@", "\\|", "12345"]
Define a word list with an interpolation:
iex(2)> x = 5 5 iex(3)> ~w(one two #{x} five#{x} "#{x}") ["one", "two", "5", "five5", "\"5\""]