Skip to content

Instantly share code, notes, and snippets.

@cdesch
Last active March 10, 2019 11:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cdesch/867d8d9a8aa2ae78af64f1d179fec89d to your computer and use it in GitHub Desktop.
Save cdesch/867d8d9a8aa2ae78af64f1d179fec89d to your computer and use it in GitHub Desktop.
elixir regex Cheat sheet
iex(1)> s1 = "Hello, World!"
"Hello, World!"
iex(2)> s2 = "ボリスくん"
"ボリスくん"
iex(3)> Regex.scan(~r/\S/, s1)
[["H"], ["e"], ["l"], ["l"], ["o"], [","], ["W"], ["o"], ["r"], ["l"], ["d"],
["!"]]
iex(4)> Regex.scan(~r/\S/, s2)
[[<<227>>], [<<131>>], [<<156>>], [<<227>>], [<<131>>], [<<170>>], [<<227>>],
[<<130>>], [<<185>>], [<<227>>], [<<129>>], [<<143>>], [<<227>>], [<<130>>],
[<<147>>]]
iex(5)> Regex.scan(~r/\w/, s2)
[[<<227>>], [<<227>>], [<<170>>], [<<227>>], [<<227>>], [<<227>>]]
iex(6)> Regex.scan(~r/\w/, s1)
[["H"], ["e"], ["l"], ["l"], ["o"], ["W"], ["o"], ["r"], ["l"], ["d"]]
iex(7)> Regex.match?(~r/^.*\.jpg$/, "file.jpg")
true
iex(8)> Regex.match?(~r/^.*\.(jpg|png)$/i, "file.jpg")
true
iex(9)> Regex.match?(~r/^.*\.(jpg|png)$/i, "file.png")
true
iex(10)> Regex.match?(~r/^.*\.(jpg|png)$/i, "file.gif")
false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment