Background
We have a simple string of variable size and we want the final 4 characters of the string. Our goal is to achieve this via pattern matching. No special reason, just trying to learn.
Code
This is what we have tried thus far:
<< _, ext :: bytes-4 >> = "my_file_name.exs"
<< _, ".", ext :: bytes-3 >> = "my_file_name.exs"
Trying both lines of code in IEx fails.
Questions
- Is it possible to pattern match a bitstring at the end of the string? (we know it works at the start)
- Are we doing something wrong? If so, what?