What from established Elixir “ecosystem” would you guys suggest for parsing out tokens embedded in a string. In this particular case tokens are embedded with double curly braces. Something like:
"This is a string with {{token0}} and {{token1}} embedded"
But suggestion for a generic approach would be appreciated.
You could take a look at gettext, which does do that for replacements in translatable strings. It’s essentially using a bunch of :binary api to handle the job.
Can’t speak for best practices, but here’s a quick and dirty regex:
iex(1)> string = "This is a string with {{token0}} and {{token1}} embedded"
"This is a string with {{token0}} and {{token1}} embedded"
iex(2)> Regex.scan(~r/{{(.*)}}/U, string, capture: :all_but_first)
[["token0"], ["token1"]]