This issue is not caused by your JavaScript code or regex itself, itis a Copilot output formatting bug,
not a regex syntax issue.
When Copilot generates code that includes backslashes (\), it sometimes fails to escape them correctly
depending on how the editor or chat window renders code blocks. That’s why regexes like /[\\w]+/ may appear
broken as /[w]+/ or similar, the single backslash gets lost in rendering.
Ways to work around this:
Ask Copilot to escape the regex explicitly like:
“Write the regex, but escape all backslashes as \\\\ for display.”
This forces it to double-escape, which survives markdown parsing.
Request the code as a downloadable file or JSON string like:
“Output the regex as a JSON string or inside triple backticks (```).”
This ensures correct formatting even if the Copilot UI strips escape sequences.
- Copy directly from Copilot’s code suggestion panel.
The inline code completion view usually contains the correct regex.
- Avoid asking Copilot to print regexes in plain text.
Markdown and Copilot’s chat rendering often corrupt those.