예제 #1
0
$r->__flags = '-xism';
$r->add('de');
$re = $r->re();
is("{$re}", "(?{$xism}de)", 'de');
$re2 = $r->re();
is("{$re2}", "(?{$xism}de)", 'de again');
$r = new Regexp_Assemble(['lookahead' => 1]);
is($r->add('car', 'cart', 'card', 'carp', 'carion')->as_string(), 'car(?:(?=[dipt])(?:[dpt]|ion))?', 'lookahead car carp cart card carion');
$r = new Regexp_Assemble(['anchor_word' => 1]);
is($r->add('ab', 'cd', 'ce')->as_string(), '\\b(?:c[de]|ab)\\b', 'implicit anchor word via method');
$r = new Regexp_Assemble(['anchor_word_end' => 1]);
is($r->add('ab', 'cd', 'ce')->as_string(), '(?:c[de]|ab)\\b', 'implicit anchor word end via method');
$r = new Regexp_Assemble(['anchor_word' => 0]);
is($r->add('ab', 'cd', 'ce')->as_string(), '(?:c[de]|ab)', 'no implicit anchor word');
$r = new Regexp_Assemble(['anchor_word' => 1]);
is($r->anchor_word_end(0)->add('ab', 'cd', 'ce')->as_string(), '\\b(?:c[de]|ab)', 'implicit anchor word, no anchor word end');
$r = new Regexp_Assemble();
is($r->anchor_word_begin(1)->add('ab', 'cd', 'ce')->as_string(), '\\b(?:c[de]|ab)', 'implicit anchor word begin');
$r = new Regexp_Assemble();
is($r->add('ab', 'cd', 'ce')->anchor_line()->as_string(), '^(?:c[de]|ab)$', 'implicit anchor line via new');
$r = new Regexp_Assemble();
is($r->add('ab', 'cd', 'ce')->anchor_line_begin()->as_string(), '^(?:c[de]|ab)', 'implicit anchor line via method');
$r = new Regexp_Assemble();
is($r->anchor_line_begin()->anchor_line(0)->add('ab', 'cd', 'ce')->as_string(), '(?:c[de]|ab)', 'no implicit anchor line via method');
$r = new Regexp_Assemble();
is($r->add('ab', 'cd', 'ce')->anchor_string()->as_string(), '\\A(?:c[de]|ab)\\Z', 'implicit anchor string via method');
$r = new Regexp_Assemble();
is($r->add('ab', 'cd', 'ce')->anchor_string_absolute()->as_string(), '\\A(?:c[de]|ab)\\z', 'implicit anchor string absolute via method');
$r = new Regexp_Assemble(['anchor_string_absolute' => 1]);
is($r->add('de', 'df', 'fe')->as_string(), '\\A(?:d[ef]|fe)\\z', 'implicit anchor string absolute via new');
$r = new Regexp_Assemble(['anchor_string_absolute' => 1, 'anchor_string_begin' => 0]);