} } } return $result; } } $a = Exp::Lit("a"); $b = Exp::Lit("b"); $c = Exp::Lit("c"); $aa = Exp::Conj($a, Exp::Many($a)); // one or more 'a' $bb = Exp::Conj($b, Exp::Many($b)); // one or more 'b' $cc = Exp::Conj($c, Exp::Many($c)); // one or more 'c' $regex = Exp::Many(Exp::Conj(Exp::Disj($aa, $bb), $cc)); $string = "acbbccaaacccbbbbaaaaaccccc"; echo "regex = " . $regex . "\n"; echo "string = \"" . $string . "\"\n"; echo "The recognized prefixes are:\n"; $result = []; for ($i = 0; $i <= strlen($string); ++$i) { $test = substr($string, 0, $i); if ($regex->recognize($test)) { $result[] = "\"" . $test . "\""; } } // printing things nicely echo "["; $start = true; foreach ($result as $s) {