in reply to REgular expression to check the string that allows "a","b" and "c" to occur only once in any order.
I'm not sure whether this is in the rules but it does work. The code below sorts the data before matching. This makes the match fairly trivial since you need to look for the string abc without a an extra "a" or "c".
#! /usr/bin/perl -w use strict; my @testdata = qw (abc cba cab bac bba cbc bbc abcdefg 0a2c3bc); foreach (@testdata) { my $test = join '', sort split //, lc $_; $test =~ /[^a]*abc(?!c)[^c]*/ ? print "Matched $_\n" : print "Didn +'t match $_\n"; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: REgular expression to check the string that allows "a","b" and "c" to occur only once in any order.
by ww (Archbishop) on Dec 11, 2007 at 13:31 UTC |
In Section
Seekers of Perl Wisdom