in reply to regular xpression stuff

Looks terrific but works:
@to_check=('bat','bbat','brat'); for (@to_check){ if (/^([bat])(?!\1)([bat])(?!\2)([bat])(?!\3)/){ # do something } }
Just create regexp dynamically.

Replies are listed 'Best First'.
Re: Re: regular xpression stuff
by gt8073a (Hermit) on Jan 21, 2002 at 01:50 UTC
    if (/^([bat])(?!\1)([bat])(?!\2)([bat])(?!\3)/){</i>

    This does not entirely work, 'bab', for instance, passes the match.

    the following modified version works, but it is not too elegant, just imagine checking a 5 letter word!

    if (/^([bat])(?!\1)([bat])(?!\2|\1)([bat])(?!\3|\2|\1)/){

    Will perl for money
    JJ Knitis
    (901) 756-7693
    gt8073a@industrialmusic.com

      For any word:
      my $set='bat'; my $regexp; for (my $i=1;$i<=length($set);$i++){ my $x=join '|', map {"\\$_"} 1..$i; $regexp.="([$set])(?!$x)"; } if (/^$regexp/){ # do something }
      Terrible... :-)