regex that can distinguish PHP tags contained in HTML tags

I need a javascript regex that can distinguish between PHP tags in HTML tags and PHP tags outside of HTML tags.e.g.\[code\]<input type="text" <? print '1'; ?> value="http://stackoverflow.com/questions/3716097/<? print'2'; ?>"><? print '3';?>\[/code\]So I need a regex to pull out:\[code\]<? print '1'; ?> and <? print '2'; ?>\[/code\]And another regex to pull out:\[code\]<? print '3';?>\[/code\]At the moment I have this regex which pulls out all PHP tags regardless of where they are:\[code\]/\n?<\?(php)?(\s|[^\s])*?\?>\n?/ig\[/code\]
 
Back
Top