awk: compose regex in variable and then use its contents like $0 ~ var

A question to the awk pundits:
I was thinking about composing a regex in a variable and then use its contents like $0 ~ var instead of $0 ~ /r/. Sort of indirection. Did someone run into this? Is it possible at all?

Try the match(string, regex) function it is meant for that purpose.

1 Like

Yes, it works just like that. You don't need to store // in the string, either.

Rats! You got me there. I stumbled over it several times but it just did not trigger...
And Yes, Corona668, not only don't you need //, they will kill the match.