replaceRE to extract part of a URL

I’m trying to use replaceRE to extract the iTunes podcast ID from a URL.

This code is from my header.html partial.

{{ if .Site.Params.Podcast.enable }}
  <meta name="apple-itunes-app" content="app-id={{- replaceRE "id(\d{10})" "$1" .Site.Params.Podcast.iTunes -}}" />
{{ end }}

I’m getting an invalid syntax error, but I can’t see where I’ve gone wrong.

You need to escape it properly. See:

Thanks @alexandros.

I’d seen that thread come up in searching the forum, but thought it wasn’t going to be my problem since the regex in that thread seemed much more complex than what I was aiming for!

For the sake of those searching here later, here’s the solution I came up with to extract the iTunes ID from a URL:

(Though if anyone has a more elegant solution, I’d love to hear it!)