Repository: vscode
Issue: Snippets: False usage of variable creates regex parsing error
Labels: bug,snippets

Type: <b>Bug</b>

Good day, 

I have encountered that false usage of variables in snippets can lead to side effects in regex parsing.

This is a minimized example of the actual used snippet. The snippet's last line is incorrect since the variable does not exist. 
The regex used here creates a header guard of the current file in upper case while the directory until "Source" is cut.

```
"C++ header guard": {
        //"scope": "C,C++",
        "prefix": "test_guard",
        "body": [
            "// Define to prevent recursive inclusion -------------------------------------",
            "",
            "#ifndef ${TM_FILEPATH/(?:^.*\\\\Source\\\\)?(\\w+)\\W?/${1:/upcase}_/g}",
            "#define ${TM_FILEPATH/(?:^.*\\\\Source\\\\)?(\\w+)\\W?/${1:/upcase}_/g}",
            "",
            "//!< @todo ${file_name} description",
        ],
        "description": "C++ header guard",
        //"isFileTemplate": true
    }
```

This expected result for the test file is:

```
// Define to prevent recursive inclusion -------------------------------------

#ifndef COMMON_CONFIGURATION_TEST_HPP_
#define COMMON_CONFIGURATION_TEST_HPP_

//!< @todo file_name description
```

but for whatever reason, comma seperators are inserted.

```
// Define to prevent recursive inclusion -------------------------------------

#ifndef COMMON,_CONFIGURATION,_TEST,_HPP,_
#define COMMON,_CONFIGURATION,_TEST,_HPP,_

//!< @todo file_name description
```


Removing the wrong usage of the variable in the last line of the snippet also removes this issue.
But it is very unexpected that the regex result depends on a completely different line in the snippet. It took me a long time to catch this dependency believing the used regex was false.
I would be happy if you can have a look if this dependency can be removed for developers falling into the same trap in the future.

VS Code version: Code 1.93.0 (4849ca9bdf9666755eb463db297b69e5385090e3, 2024-09-04T13:02:38.431Z)
OS version: Windows_NT x64 10.0.19045
Modes:

<details>
<summary>System Info</summary>

|Item|Value|
|---|---|
|CPUs|12th Gen Intel(R) Core(TM) i7-1260P (16 x 2496)|
|GPU Status|2d_canvas: enabled<br>canvas_oop_rasterization: enabled_on<br>direct_rendering_display_compositor: disabled_off_ok<br>gpu_compositing: enabled<br>multiple_raster_threads: enabled_on<br>opengl: enabled_on<br>rasterization: enabled<br>raw_draw: disabled_off_ok<br>skia_graphite: disabled_off<br>video_decode: enabled<br>video_encode: enabled<br>vulkan: disabled_off<br>webgl: enabled<br>webgl2: enabled<br>webgpu: enabled<br>webnn: disabled_off|
|Load (avg)|undefined|
|Memory (System)|31.71GB (18.94GB free)|
|Screen Reader|no|
|VM|0%|
</details><details><summary>Extensions (33)</summary>

Extension|Author (truncated)|Version
---|---|---
gitlens|eam|15.4.0
boost-test-adapter-xnely|Eri|3.2.8
jenkins-pipeline-linter-connector|jan|1.2.0
hex-fmt|ker|1.0.0
jenkins-doc|Maa|1.7.0
cortex-debug|mar|1.12.1
debug-tracker-vscode|mcu|0.0.15
memory-view|mcu|0.0.25
peripheral-viewer|mcu|1.4.6
rtos-views|mcu|0.0.7
rainbow-csv|mec|3.12.0
git-graph|mhu|1.30.0
debugpy|ms-|2024.10.0
python|ms-|2024.12.3
vscode-pylance|ms-|2024.8.2
jupyter|ms-|2024.8.0
jupyter-keymap|ms-|1.1.2
jupyter-renderers|ms-|1.0.19
vscode-jupyter-cell-tags|ms-|0.1.9
vscode-jupyter-slideshow|ms-|0.1.6
remote-ssh|ms-|0.114.1
remote-ssh-edit|ms-|0.86.0
remote-wsl|ms-|0.88.2
cmake-tools|ms-|1.19.51
cpptools|ms-|1.21.6
cpptools-extension-pack|ms-|1.3.0
remote-explorer|ms-|0.4.3
rust-analyzer|rus|0.3.2104
code-spell-checker|str|3.0.1
cmake|twx|0.0.17
vscode-lldb|vad|1.10.0
vscode-icons|vsc|12.8.0
vscode-proto3|zxh|0.5.5

(1 theme extensions excluded)

</details><details>
<summary>A/B Experiments</summary>

```
vsliv368cf:30146710
vspor879:30202332
vspor708:30202333
vspor363:30204092
vswsl492cf:30256860
vscod805cf:30301675
binariesv615:30325510
vsaa593cf:30376535
py29gd2263:31024239
c4g48928:30535728
azure-dev_surveyone:30548225
a9j8j154:30646983
962ge761:30959799
pythongtdpath:30769146
welcomedialog:30910333
pythonnoceb:30805159
asynctok:30898717
pythonmypyd1:30879173
h48ei257:31000450
pythontbext0:30879054
accentitlementst:30995554
dsvsc016:30899300
dsvsc017:30899301
dsvsc018:30899302
cppperfnew:31000557
dsvsc020:30976470
pythonait:31006305
dsvsc021:30996838
g316j359:31013175
a69g1124:31058053
dvdeprecation:31068756
dwnewjupyter:31046869
newcmakeconfigv2:31071590
impr_priority:31102340
nativerepl2:31104044
refactort:31108082
pythonrstrctxt:31112756
flighttreat:31119336
wkspc-onlycs-t:31132770
wkspc-ranged-c:31125598
fje88620:31121564

```

</details>

<!-- generated by issue reporter -->