开发者

regular expression to replace '<?' by '<?php'

Hi i'm trying to find all occurences of '<?' in my php code. I use eclipse for this, and i tried to search for the folowing pattern: "<\?^[p]" in the hope thi开发者_StackOverflow中文版s would return me all <? occrences, but not the <?php ones..

What's wrong about the regex? I thought I had figured out regular expressions, but it seams like i still have a long way to go :(


try this: <\?[^p]


I'm not familiar with Eclipse's regular expression language but I'd imagine you want this:

"<\?[^p]"

The difference is:

  • [^p] means any character apart from p
  • ^[p] means the start of a new line followed by a p.

But you should check the manual for Eclipse to find out the exact regular expression syntax that Eclipse uses.


If all fails, you could use a trick with no regexes: replace your <?php occurrences with something else (like for example THE_PHP_TAG), then search for <?, then replace THE_PHP_TAG back to <?php.


Edited

From what I understand you want to change <? to <?php. Try replacing <\?(?!php) with <?php. (This will prevent <?php from turning into <?phpphp).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜