Assign block content to variables? Or run findRegex over block content?

Is it possible to assign a block to a variable, to then manipulate in the base before outputting?

For example, could I change:

<!DOCTYPE html>
<html>
<body>
    <main >
        {{- block "main" . }}{{- end }}
    </main>
</body>
</html>

to something along the lines of:

{{$mainBlock := block "main" . }}
<!DOCTYPE html>
<html>
<body>
    <main >
        {{ $mainBlock }}
    </main>
</body>
</html>

The main reason is that I’d like to use findRegex on the $mainBlock content and manipulate the head based on that.

I don’t think so.

You might want to approach your issue from a completely different place. What you would be doing, if you could do it, would be using Hugo to create the main content and then taking that main content and using Hugo to change it. Working twice on something you could do proper just once.

Much further down the chain this content is created. That is the place to start working on your requirements. That’s what for instance .Scratch is for if you need to do more complicated stuff.