Reputation: 5879
I have the following line:
<?php echo $this->__("mytext");?>somesometext")moretext
and I need a regular expression to grab 'mytext'. The best I could come up with is:
/\$this->__\([\'"](.*)[\'"]\)/
but in this case it returns:
mytext");?>somesometext
Can anyone get this to work?
Upvotes: 1
Views: 123
Reputation: 655815
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.
Upvotes: 3
Reputation: 1331
/\$this->__\([\'"](.*?)[\'"]\)/
The ?
makes the *
quantifier ungreedy.
Upvotes: 2
Reputation: 83692
/\$this->__\([\'"](.*?)[\'"]\)/
should work. The ?
switches the match-mode to ungreedy.
Upvotes: 2