setting limit of preg_match in php 7.2

Solution for setting limit of preg_match in php 7.2
is Given Below:

I have issue in php preg_match..
I tried using preg_match to check this string..


echo count(explode('.', $txt)) . "<br>";
echo strlen($txt) , "<br>";
if(preg_match("/[a-z]+(?:([.][a-z]+)*)/i", $txt)) {
    echo "A match was found.";
} else {
    echo "A match was not found.";

But I think there is limit in preg_match.. the total count after I explode the dot is 1638, more than 1638, it returns not match.
But when I tried using phpliveregex or regex 101 it can match the regex..

so here is the complete explanation..
I created a program for checking a format..

continue from this issue Javascript string match specific regex

User can input anything in textarea, as long as it’s correct then it will retrive the data, but when user input wrong format, I should remove the wrong format by using preg_replace and retrive a correct format, when none of format is correct, then it will return error message..

this not 1 format only, there are about 10 formats I should check..
so this is not just a simple to explode the ., +, * or use cytpe_alpha().

The conclusion is the program or the product owner does not care what user input into the text area, they can input 10 formats into the textarea.. as long as I can check and passed the format, then it all be good..

example of wrong input that I should fix into correct format..,,,,.,.,pencil,

so after I correct the format, it will be like this..*2*3*4=24+50-50*30*20=0+4*8=32

can anyone help with this issue?

It appears that you have reached the memory limit on “capturing”. If you simply don’t capture any substrings, you’ll be just fine.

Code: (Demo)

$txt="" . str_repeat('', 815);

for ($i = 0; $i < 5; ++$i) {
    $txt .= '';
    echo count(explode('.', $txt)) . "n";
    echo strlen($txt) . "n";
    if (preg_match("/[a-z]+(?:.[a-z]+)*/i", $txt, $match)) {
        echo "A match was found." . strlen($match[0]);
    } else {
        echo "A match was not found.";
    echo "n---n";


A match was found.6535
A match was found.6543
A match was found.6551
A match was found.6559
A match was found.6567

About the error:

You are getting error constant 6.


preg_last_error_msg() isn’t available until PHP8.

I see some good answers at: PHP PREG_JIT_STACKLIMIT_ERROR – inefficient regex

If preg_match() is proving to be unsuitable/miserable for your requirements, then stop using it. There are other available tools to determine if a string is strictly comprised of dot-separated alphabetical substrings.

function isDotSeparatedAlphabetical($string) {
    foreach (explode('.', $string) as $word) {
        if (!ctype_alpha($word)) {
            return false;
    return true;

$txt="" . str_repeat('', 815);

for ($i = 0; $i < 5; ++$i) {
    $txt .= '';
    var_export(['length' => strlen($txt), 'verdict' => isDotSeparatedAlphabetical($txt)]);
    echo "n---n";