awk gsub using variable for pattern matching

Viewed 13299

gsub(pattern, replacement, target): allows a variable to be used for pattern, but does not let me do regular expression.

gsub(/pattern/, replacement, target): lets me do regular expression, but I cannot use a variable for the pattern.

Is there a way to get both variable pattern and regex to work in gsub? I'd like to stick with awk, no sed or shell.

2 Answers
Related