Regex string substitution and capture groups


#1 nimaimalle

I'm trying to do something like this, but I'm getting a literal "$1" substituted instead of the value of the capture group.

if $data =~ s/(\[[^\]]+\])/"$1"/g log_info($1);

$data ends up containing a "$1" while the log_info statement correctly logs the value of captured group $1.

Is there a way to use s/// and capture groups in the substitution? I also tried \1 and \\1.

#2 b0ti Nxlog ✓
#1 nimaimalle
I'm trying to do something like this, but I'm getting a literal "$1" substituted instead of the value of the capture group. if $data =~ s/(\[[^\]]+\])/"$1"/g log_info($1); $data ends up containing a "$1" while the log_info statement correctly logs the value of captured group $1. Is there a way to use s/// and capture groups in the substitution? I also tried \1 and \\1.

That's not supported currently but it's on the roadmap.