I need a javascript regex that can distinguish between PHP tags in HTML tags and PHP tags outside of HTML tags.
e.g.
<input type="text" <? print '1'; ?> value="<? print '2'; ?>">
<? print '3';?>
So I need a regex to pull out:
<? print '1'; ?> and <? print '2'; ?>
And another regex to pull out:
<? print '3';?>
At the moment I have this regex which pulls out all PHP tags regardless of where they are:
/\n?<\?(php)?(\s|[^\s])*?\?>\n?/ig
This is a very complex thing to do, and I very much doubt it can be solved by regular expressions. This does depend to some degree on how complex the PHP that you want to extract is, but there are many cases to consider:
Why do you need to do this with JavaScript and regular expressions?