Это не красиво, но делает работу.
defmodule UglyParser do
def main do
str = """
### image_date: 23/01/2019 ###
pool2 wxcs 2211
pool3 wacs 1231
### line_count: 1 ###
"""
[header, content, footer] = String.split(str, ~r/(?:#\s*\n)|(?:\n\s*#)/, trim: true)
header = to_pair(header)
footer = to_pair(footer)
content = {:content, String.trim(content) |> String.replace(~r/\n\s*/, "\n")}
Enum.into([header, footer, content], %{})
end
defp to_pair(str) do
String.replace(str, "#", "")
|> String.trim()
|> String.split(": ")
|> (fn [key, value] -> {String.to_atom(key), value} end).()
end
end