Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP code generator uses wrong quotes for $substr in substitution #2407

Closed
ismael-miguel opened this issue Jan 23, 2025 · 1 comment
Closed

Comments

@ismael-miguel
Copy link

Code Generator Language

PHP

Code Snippet

Just use the $group syntax (to use a value from a named group) for the substitution value, in substitution name.

Example: https://regex101.com/r/Iqww6d/1
In this example, I use the named group a

The generated code will contain this:

<?php

// ...

$substr = "$a"; // <-- the wrong quotes

// ...

This will try to use string interpolation to show the contents of the variable $a as the replacement value.
This can cause fatal errors or surprising results.

Alternatively, escape the $ with \, like this: "\$a".


Additinally, using the syntax ${a} for the replacement value will be worse, since that is the deprecated in PHP 8.2.
And has the same problems as before.

@working-name
Copy link
Collaborator

Hi @ismael-miguel,

The replacement notation you're using is regex101-specific, as stated in the quick reference entry for it. PHP, as far as I know, does not support calling capture groups by name, only by numerical ID.

@working-name working-name closed this as not planned Won't fix, can't repro, duplicate, stale Feb 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants