How to obtain URL prefix with "replaceRE" function?

Greetings, can anyone explain the correct way to extract the URI “scheme” prefix from a URL? (string before ://)

For example, how would you obtain the prefix string irc from irc:// and apt from apt://hugo

Many thanks in advance.

The split template function could make your life a bit easier. Try the following:

{{ index (split $url "://") 0 }}

Replace $url with the url from which you would like to obtain the url prefix.

1 Like

Hi DC, appreciate the swift response.

Your example works perfectly and far simpler than originally thought (“replaceRE”), the missing ingredient was the “index” function for reading the array output many other Go/Hugo functions return.

Many thanks again!