assert($s->index('/21/') === -1); $s->pos(5); assert($s->index('/0/') === -1); assert($s->index('/6/') === 6); // Now the automation functions $s->string('012 45 '); $s->addPattern('zero', '/0/'); $s->addPattern('one-dummy', '/1/'); $s->addPattern('one', '/1/'); $s->addPattern('two', '/2/'); $s->addPattern('digit', '/\\d/'); $s->addPattern('four', '/4/'); $s->removePattern('one-dummy'); // 4 should never match, digit will take precedence. // one-dummy should never match, it was removed. $out = $s->nextMatch(); assert($out === array(0 => 'zero', 1 => 0)); assert($s->match() === '0'); assert($s->matchPos() === 0); assert($s->pos() === 1); // don't log this one $out = $s->nextMatch(false); assert($out === array(0 => 'one', 1 => 1)); // match info and pos unchanged assert($s->match() === '0'); assert($s->matchPos() === 0); assert($s->pos() === 1); // do log it now $out = $s->nextMatch(); assert($out === array(0 => 'one', 1 => 1)); assert($s->match() === '1');