I need to find all short PHP tags.
The regex for it <\?(?!php)
but I can not use it in vim.
How to "convert" it to vim?
The <= tag is called short open tag in PHP. To use the short tags, one must have to enable it from settings in the PHP. ini file. First of all ensure that short tags are not disabled, To check it, go into php. ini file On line 77 .
There are four different pairs of opening and closing tags which can be used in php.
php and ?>. These are called PHP's opening and closing tags. Statements witihn these two are interpreted by the parser. PHP script within these tags can be embedded in HTML document, so that embedded code is executed on server, leaving rest of the document to be processed by client browser's HTML parser.
For me this one worked fine:
<\?(?!php|xml)
The best way to find short-tags in vim is to find all occurrences of <?
not followed by a p
:
/<?[^p]
The reason your regex is failing in vim is because /?
finds literal question marks, while \?
is a quantifier; /<\?
in vim will attempt to find 0 or 1 less-than signs. This is backwards from what you might expect in most regular expression engines.
If you want to match short tags that are immediately followed by a new line, you cannot use [^p]
, which requires there to be something there to match which isn't a p
. In this case, you can match "not p or end-of-line" with
/<?\($\|[^p]\)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With