Regex - catastrophic backtracking - multi line


i have a pattern which matches my translation strings. It works fine except when the text gets long (over 1000 chars)
$pattern = ‘/$this->translate((?:\W*\n*)'((.\n*(\\')))'(?:\W*\n*.))/imU’;

It stops working with an PREG_JIT_STACKLIMIT error. So backtracing is for this pattern as it looks pretty bad.

What should it match:

$this->translate('some text to translate s'and some %s
new lines… and should also work for long texts with many %s new lines and ' in it ', array(‘hello’, ‘world’)

The array at the end of the translate function is optional. I’ve did some research and found this article:

But i didn’t managed to apply this to my case. The key point is, that i must not match ' in the text, but have to stop at a not escaped ’ .

Does anyone have a suggestion how this pattern could be improved?

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.