Last active
March 10, 2019 11:03
-
-
Save cdesch/867d8d9a8aa2ae78af64f1d179fec89d to your computer and use it in GitHub Desktop.
elixir regex Cheat sheet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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