Beispiel #1
0
assert($s->scanUntil('/5/') === '01234');
assert($s->match() === '01234');
assert($s->matchGroup(0) === '01234');
assert($s->matchGroups() === array(0 => '01234'));
assert($s->pos() === 5);
// now check index
$s->reset();
assert($s->index('/0/') === 0);
assert($s->index('/2/') === 2);
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);