Finding all PHP short tags
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]\)
Using (a recent version of) grep
:
grep -P '<\?(?!(php|xml|=))' *
To find all files with a <?
short tag:
find -type f -exec grep -IlP '<\?(?!(php|xml|=))' {} +
Note that these do not match the <?=
short tag, as that is always available since 5.4.0 and it does no harm either way. (Whereas <?
does harm if allow_short_tags = Off
.)