ok($re->mvar(1), 'u', 'match pattern-4 capture 2'); ok($re->mvar(2) == 350, 'match pattern-4 capture 3'); $target = 'c-2048'; ok($re->match($target), "match pattern-4 {$target}"); ok($re->mvar(0), $target, 'match pattern-4 capture 4'); ok($re->mvar(1) == 2048, 'match pattern-4 capture 5'); ok(!$re->mvar(2), 'match pattern-4 undef'); is_deeply($re->mbegin, [0, undef, undef, 2], 'match pattern-3 mbegin'); is_deeply($re->mend, [6, undef, undef, 6, undef], 'match pattern-3 mend'); // } $re = new Regexp_Assemble(['track' => 1]); $re->add('^c-\\d+$')->add('^c-\\w+$')->add('^c-[aeiou]-\\d+$'); // SKIP: { // skip( "/?{...}/ and \\d+ cause a panic in this version of perl ($])", 6 ) if $PERL_VERSION_5_005; ok(!$re->match('foo'), 'match pattern-5 foo'); ok(!$re->mvar(2), 'match pattern-4 foo novar'); $target = 'c-u-350'; ok($re->match($target), "match pattern-5 {$target}"); ok($re->mvar(0), $target, 'match pattern-5'); ok(!$re->mvar(1), 'match pattern-5 no capture 2'); ok(!$re->mvar(2), 'match pattern-5 no capture 3'); // } $re = new Regexp_Assemble(['track' => 1]); $re->add('^cat')->add('^candle$')->flags('i'); // SKIP: { // skip( "match()/matched() return undef in this version of perl ($])", 8 ) if $PERL_VERSION_5_005; ok(!$re->match('foo'), 'not match pattern-6 foo'); $target = 'cat'; ok($re->match($target), "match pattern-6 {$target}"); is($re->matched, '^cat', "match pattern-6 {$target} re"); $target = 'CATFOOD';
unlike($target, "/{$ra}/", "fail after reset {$target}"); } $ra->add('who', 'what', 'where', 'why', 'when'); foreach (array('unfooled', 'disembark', 'vibration') as $target) { unlike($target, "/{$ra}/", "fail ok {$target}"); } foreach (array('snowhouse', 'somewhat', 'nowhereness', 'whyever', 'nowhence') as $target) { like($target, "/{$ra}/", "new match ok {$target}"); } $ra->reset()->mutable(1); unlike('nothing', "/{$ra}/", "match nothing after reset"); $ra->add('^foo\\d+'); like('foo12', "/{$ra}/", "match 1 ok foo12"); unlike('nfoo12', "/{$ra}/", "match 1 nok nfoo12"); unlike('bar6', "/{$ra}/", "match 1 nok bar6"); ok(!$ra->mvar(), 'mvar() undefined'); $ra->add('bar\\d+'); like('foo12', "/{$ra}/", "match 2 ok foo12"); unlike('nfoo12', "/{$ra}/", "match 2 nok nfoo12"); like('bar6', "/{$ra}/", "match 2 ok bar6"); $ra->reset()->filter(function ($arr) { $r = []; foreach ($arr as $_) { if (preg_match("/\\d /", $_)) { $r[] = $_; } } return !count($r); }); $ra->add('1 2 4'); $ra->insert('1', '2', '8*');