I'm trying to use regex to select instances where something like <? (a php construct is used but not <?php. I've tried several iterations on regextester but have failed. Here's the latest <\?(?!<\?php)
Basically this is what I want. it covers all the variations in my document
<?php foo ?> //should not match
<? bar ?> //should match '<?'
<?=foobar ?> //should match '<?='
<?xml barbar ?> //should not match
I'm new to regex so any help would be appreciated
Edit: With the problems with the answers posted I'm adding one more condition to match
<?php foo ?> //should not match
<? bar ?> //should match '<?'
<?bar ?> //should match '<?' there could be any character after ?
<?=foobar ?> //should match '<?='
<?xml barbar ?> //should not match
To summarize, I'm only trying to match <? or <?= not the complete line they occur in.
Edit 2: Basically the logic of the expression should be: match <? or <?= but not if followed by `php' or 'xml'
<\?[^\w\s]*+(?!(?:php|xml)\b)but not sure if there are any other exceptions. However, I think I found a more generic approach, please see my answer.<?=foobar ?>and<?bar ?>would throw syntax errors and would fail to execute if run by PHP, as a valid opening tag must be followed by some sort of whitespace (space, newline, tab, etc). So if your goal to find valid php code, those two would actually not be valid.<?php, cauz it's valid already