开发者

Need php regex between 2 sets of chars

I 开发者_运维知识库need a regular expression for php that outputs everything between <!--:en--> and <!--:-->. So for <!--:en-->STRING<!--:--> it would output just STRING.

EDIT: oh and the following <!--:--> nedds to be the first one after <!--:en--> becouse there are more in the text..


The one you want is actually not too complicated:

/<!--:en-->(.*?)<!--:-->/gi

Your matches will be in capture group 1.

Explanation:

The .*? is a lazy quantifier. Basically, it means "keep matching until you find the shortest string that will still fit this pattern." This is what will cause the matching to stop at the first instance of <!--:-->, rather than sucking up everything until the last <!--:--> in the document.

Usage is something like preg_match("/<!--:en-->(.*?)<!--:-->/gi", $input) if I recall my PHP correctly.


If you have just that input

$input  = '<!--:en-->STRING<!--:-->';

You can try with

$output = strip_tags($input);


Try:

^< !--:en-- >(.*)< !--:-- >$

I don't think any of the other characters need to be escaped.


<!--:en--\b[^>]*>(.*?)<!--:-->

This will match the things between your tags. This will break if you nest your tags, but you didnt say you were doing that :)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜