Regex match in functions?

Hello I have the following code:

defmodule ElixirSecImage do
    def isbase64(path) do
        Regex.match?(~r|([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{4}|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)|, path)
    end
end

But it gives me the following error:
“do” is missing terminator “end”. unexpected token: “)” at line 3
How can I use Regex.match? in the function?

1 Like

[quote=“Mot, post:1, topic:11928”]

defmodule ElixirSecImage do
    def isbase64(path) do
        Regex.match?(~r|([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{4}|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)|, path)
    end
end
```[/quote]
Inside the regular expression you're using the same character that you're using as a sigil delimiter, so the parsing of it terminates early and stuff gets wonky. If you switch to `<` and `>` it'll run. At least for me.

This is probably because of your delimiters beeing used inside of the RegEx literall.

Try " instead (~r"...").

1 Like

Ahhh! Thank you! Yes that worked like a charm. How could I miss that.

1 Like