regex_replace() captured string doesn't work
- Dominant language
- Go
- Stars
- 15.8k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
#### Community Note
* Please vote on this issue by adding a 👍 [reaction](https://blog.github.com/2016-03-10-add-reactions-to-pull-requests-issues-and-comments/) to the original issue to help the community and maintainers prioritize this request
* Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
* If you are interested in working on this issue or have submitted a pull request, please leave a comment
#### Overview of the Issue
The reference to captured string in `regex_replace()` doesn't work as expected.
#### Reproduction Steps
From :
```
> regex_replace("-ab-axxb-", "a(x*)b", "${1}W")
-W-xxW-
```
My actual result:
```
$ packer console -config-type=hcl2
> regex_replace("-ab-axxb-", "a(x*)b", "${1}W")
> -1W-1W-
```
### Packer version
From `packer version`
Packer v1.8.7
### Simplified Packer Template
N/A.
### Operating system and Environment details
```
$ sw_vers
ProductName: macOS
ProductVersion: 13.4
BuildVersion: 22F66
$ uname -a
Darwin YNVWYNWVX4 22.5.0 Darwin Kernel Version 22.5.0: Mon Apr 24 20:52:24 PDT 2023; root:xnu-8796.121.2~5/RELEASE_ARM64_T6000 arm64
```
### Log Fragments and crash.log files
N/A.
Contributor guide
Research direction
Start by reproducing the discrepancy through the `regex_replace()` entry point in `packer console -config-type=hcl2`, using the example from the issue. Trace how the `${1}` replacement is interpreted and verify that the result preserves the captured strings as documented: `-W-xxW-`.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100