I’m creating a piece of code that translates a string into Morse code, but I need to check whether the string can be translated into Morse code at all. I’ve got a map that has all the translations, so I figured the most optimal way would be to check whether all the characters in the string appear in this map. Would it somehow be possible to turn this into a regex so I can simply use String.match?/2
?
@morse_dict %{
"A" => ".-",
"B" => "-...",
"C" => "-.-.",
"D" => "-..",
"E" => ".",
"F" => "..-.",
"G" => "--.",
"H" => "....",
"I" => "..",
"J" => ".---",
"K" => "-.-",
"L" => ".-..",
"M" => "--",
"N" => "-.",
"O" => "---",
"P" => ".--.",
"Q" => "--.-",
"R" => ".-.",
"S" => "...",
"T" => "-",
"U" => "..-",
"V" => "...-",
"W" => ".--",
"X" => "-..-",
"Y" => "-.--",
"Z" => "--..",
"0" => "-----",
"1" => ".----",
"2" => "..---",
"3" => "...--",
"4" => "....-",
"5" => ".....",
"6" => "-....",
"7" => "--...",
"8" => "---..",
"9" => "----.",
"." => ".-.-.-",
"," => "--..--",
"?" => "..--..",
"'" => ".----.",
"!" => "-.-.--",
"/" => "-..-.",
"(" => "-.--.",
")" => "-.--.-",
"&" => ".-...",
":" => "---...",
";" => "-.-.-.",
"=" => "-...-",
"+" => ".-.-.",
"-" => "-....-",
"_" => "..--.-",
"\"" => ".-..-.",
"$" => "...-..-",
"@" => ".--.-.",
" " => "/"
}
Thanks