0

Creating custom language injection for Regexp String in PHP

Hey all.
PHPStorm is bundled with a Language Injection for Regexp using the <<<REGEXP HEREDOC expression. I would like to also have it auto detect Regexp written in strings. For this I tried to create a custom language injection entry (see attached export).
Unfortunately, my attempt does not seem to work but I also don't understand why it wouldn't work, so I'm interested if anyone has any idea on this.
Things I want to match:

$var = "/someregex/";
preg_match("@someregexp@i","haystack",$matches);

So to this end I added the following:

+ phpLiteralExpression().withText(string().matchesBrics("^[/#@].*[/#@][gi]?$"))
Which I expected to work but doesn't... what am I doing wrong? I at first also wanted the ending group [/#@] to match using a backreference for the first group (as "([/#@])" and "\1" or "$1") but this syntax wasn't accepted and as such also didn't work :-/



Attachment(s):
regex_lang-injection.xml

6 comments

Please sign in to leave a comment.