troubleshooting Question

PHP pcre Regular Expression max characters? -- regex, preg_match

Avatar of seanhess
seanhess asked on
Regular ExpressionsPHP
5 Comments1 Solution1382 ViewsLast Modified:
PHP's preg_match seems to be failing when the subject has too many characters in it.  

This is my expression::
   preg_match('/(.*<div id="storeArea">\s*)(.*)(\s*<\/div>\s*<!--POST-BODY-START-->.*)/si', $subject, $regs)

And here is the subject
<div id="storeArea">
<div>aaa ... </div>
<div>aaa ... </div>
<div>aaa ... </div>

It will match fine on that, but if the aaa .... is made HUGELY long, it won't match any more.  I tested it with 80,000 a's in each line.  If there was only one line (div tag) of A's, it would match, but it wouldn't match 3 lines of a's.

Is there a character limit to preg_match?  Why would it behave like this?  Can I fix the regular expression?


We're sending info to a php script.  It is supposed to match a regular expression against the data.
Join our community to see this answer!
Unlock 1 Answer and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros