This Question is Possibly Answered

1 "correct" answer available (4 pts) 1 "helpful" answer available (2 pts)
6 Replies Last post: Jan 12, 2014 9:49 PM by Alexey Gopachenko  
Doqnach . Newbie 3 posts since
Jan 10, 2014
Currently Being Moderated

Jan 10, 2014 2:31 PM

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 :-/

Attachments:
Andriy Bazanov Master 4,167 posts since
May 28, 2010
Currently Being Moderated
Jan 10, 2014 2:53 PM in response to: Doqnach .
Re: Creating custom language injection for Regexp String in PHP

Hi there,

 

what am I doing wrong?

You are missing one important thing: the fact that no regex is used to describe matching string. It looks similar, but it is not a regex and this "^[/#@].*[/#@][gi]?$" simply will not work. Regex is simply too slow to be used here.

 

ATM you can only manually inject RegEx in such places as you edit them (Alt+Enter while standing inside the string).

 

Other than that: http://youtrack.jetbrains.com/issue/WI-1640

Andriy Bazanov Master 4,167 posts since
May 28, 2010
Currently Being Moderated
Jan 10, 2014 3:12 PM in response to: Doqnach .
Re: Creating custom language injection for Regexp String in PHP

so do you happen to have a link to a reference page where the syntax is explained?

I do not, unfortunately.

Liubov Melnikova JetBrains 241 posts since
Nov 8, 2013
Currently Being Moderated
Jan 10, 2014 3:33 PM in response to: Doqnach .
Re: Creating custom language injection for Regexp String in PHP

Maybe this one will be just a little bit better for your needs: http://www.jetbrains.com/phpstorm/webhelp/regular-expression-syntax-reference.html .

Alexey Gopachenko JetBrains 1,466 posts since
Aug 22, 2002
Currently Being Moderated
Jan 12, 2014 9:49 PM in response to: Doqnach .
Re: Creating custom language injection for Regexp String in PHP

We don't consider this a "user serviceable" part..

Anyway http://www.brics.dk/automaton/faq.html

plus we do some pre-processing in "matchesBrics": ' ' is replaced with <whitespacechar> and any UPPERCASE_CHAR with a group [cC].

More Like This

  • Retrieving data ...