Does Hugo support some kind of string interpolation that I could use to create my regexes?
If more than one variable is used the print way is extremely unreadable IMHO e.g.:
Removing the unnecessary brackets around the # might increase legibility a tad. Perl allows you to use variables in REs, but that’s the only language I’m aware of. Since variables in the Go template language must begin with a $, allowing something like ^(#){$level} in a RE would probably cause performance issues. And as the Go implementation of REs already omits some functionality for performance reasons … I guess, printing is the only way.
Oh, and this has been already discussed elsewhere as a simple search turns up:
FYI basically any language with string interpolation (i.e. Python, Rust, Julia, Nix, Ruby, and I can keep going for a long) support this implicitly (because it is irrelevant to regexp in general but can be used to create regexp because regex itself is / or can be treated as string).
Those links you posted have nothing to do with Hugo AFAIK there is no place in Hugo where you write Go code except in Hugo’s source code itself.
And regarding Go templates, yes I had skimmed through the docs to no avail.
“Hugo string interpolation”, “Hugo variable in regex”, “Hugo regex templates” “Hugo template as regex” typed into Hugo documentation, Hugo forums here, or Google yields nothing obviously to me usable. I had searched it all before posting a question here.
So either your simple search was not simple or it was aimed at Go which is irrelevant to Hugo.
Hugo’s templating language is based on Go’s templates. Described here:
And Hugo’s REs are based on Go’s REs (quoting from the documentation):
Go’s regular expression package implements the RE2 syntax. The RE2 syntax is a subset of that accepted by PCRE, roughly speaking, and with various caveats.
And yes, a RE can be treated as a string. And the way to interpolate a variable in a string in Hugo is `printf/printf’. Back to square one.