in reply to Re: conditional expression testing
in thread conditional expression testing

thank you guys. total misunderstanding on my part
works perfectly now
use warnings; use strict; my @dic = qw#beriberi hanabbsbbshana#; for (@dic) { my $pat = $_; print "trying to match $pat\n"; print "matched $pat\n" if $_ =~ m#^(hana)(bbs)?(?(1)\2\1|\1)$#; } my @pat = qw#AAAAG AC GC AZG ZC AAAG#; for ( @pat ) { my $pat2 = $_; print "matching $pat2\n"; print "matched $pat2\n" if $_ =~ m#[ATGC]+(?(?<=AA)G|C)$#; }

Replies are listed 'Best First'.
Re^3: conditional expression testing
by ikegami (Patriarch) on Jun 01, 2010 at 16:51 UTC
    m#^(hana)(bbs)?(?(1)\2\1|\1)$#;

    is the same as

    m#^(hana)(bbs)?\2\1$#;

    since (?(1)...) is always true. And since you don't use the captures, that can be be simplified to

    m#^hana(?:bbsbbs)?hana$#;