King2500/idea-php-advanced-autocomplete

Completion for regex captures in preg_replace

King2500 opened this issue · 0 comments

preg_replace('/a(foo)bar/i', '$<caret>', $var);
preg_replace('/a(foo)bar/i', '\<caret>', $var);
preg_replace_callback('/a(foo)bar/i', function ($matches) {
    return $matches[<caret>];
}, $var);
preg_replace_callback('/a(?<named>foo)bar/i', function ($matches) {
    return $matches['<caret>'];
}, $var);
preg_replace_callback('/a(foo)bar/i', function ($matches) {
    return $<caret> // lists all possible $matches[x] as variable with type text 'string'
}, $var);

Completion popup should show the regex part from brackets ((foo) in above example) as tail text.
If the first function parameter is a variable (like $fooRegex), field ($this->fooRegex) or constant (FOO_REGEX), it should also take that declaration into account.

Reference:
https://www.php.net/manual/de/function.preg-replace.php