Skip to content

Completion for regex captures in preg_replace #31

@King2500

Description

@King2500
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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions