0
preg_split("/({{\s*(?:(?!}}).)+\s*}})/s", file_get_contents('data.txt'));

That line makes Apache reset the connection. data.txt is approximately 12 kB.

What am I doing wrong, can I optimize the regex somehow?

Markus Hedlund
  • 23,374
  • 22
  • 80
  • 109

2 Answers2

2

Try this regular expression instead:

/({{(?>(?:[^}]|}[^}])+)}})/s

The main improvements:

  • (?>…)atomic grouping to avoid backtracking
  • (?:[^}]|}[^}])+ – no look-around, no non-greedy matching
Gumbo
  • 643,351
  • 109
  • 780
  • 844
0

Try reading the file into a variable than passing it to preg_split. I think it's file_get_contentsproblem rather thanpreg_split`.

s3v3n
  • 8,203
  • 5
  • 42
  • 56