开发者

regular expression to grab quoted text in PHP code

I have the following line:

<?php echo $this->__("mytext");?>somesometext")moretext

and I need a regular expression to gra开发者_StackOverflowb 'mytext'. The best I could come up with is:

/\$this->__\([\'"](.*)[\'"]\)/

but in this case it returns:

mytext");?>somesometext

Can anyone get this to work?


Better use PHP’s ability to parse its own code with token_get_all, step through the tokens and stop at the first T_CONSTANT_ENCAPSED_STRING token.


/\$this->__\([\'"](.*?)[\'"]\)/

The ? makes the * quantifier ungreedy.


/\$this->__\([\'"](.*?)[\'"]\)/

should work. The ? switches the match-mode to ungreedy.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜