1

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?

2
  • What can mytext be? Can it contain escaped double quotes like this: <?php echo $this->__("my \" text");?>somesometext")moretext? Commented Nov 12, 2009 at 13:18
  • @Bart Yes, it can have anything you could possibly pass to a function as a string. Commented Nov 12, 2009 at 13:21

3 Answers 3

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Even though impractical for my application, +1 for leveraging PHP tokenizer's power.
2
/\$this->__\([\'"](.*?)[\'"]\)/

The ? makes the * quantifier ungreedy.

1 Comment

Both this and Stefan's answers are correct. Picked the one that needed the rep the most.
2
/\$this->__\([\'"](.*?)[\'"]\)/

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.