in reply to regex testing for ALL of the vowels in a scalar

This is an odd case to use a regex for, actually (it kind of demonstrates a lack of understanding of what a regex is good for).

That being said, though, this:

/(?=.*a)(?=.*e)(?=.*i)(?=.*o)(?=.*u)/i
should do you pretty easily. Granted, it makes use of positive look-ahead which isn't strictly speaking "regular". The basic description of the regex is: there exists a place in the string (the beginning of the string, for example), after which exists an "a" AND after which exists an "e", etc.

To do this with a true regular expression (and hence without lookahead assertions), you'd want to do it by essentially creating a list of all 5-factorial permutations of aeiou, and, over these permutations like so (written out kind of long-hand so that the idea should be transparent):

my @regex_pieces = (); foreach my $permutation (@permutations) { my @vowels = split //, $permutation; push @regex_pieces, join(".*", @vowels); } my $regex = qr/@{[join("|", @regex_pieces)]}/i;
------------ :Wq Not an editor command: Wq

Replies are listed 'Best First'.
Re: Re: regex testing for ALL of the vowels in a scalar
by ysth (Canon) on Feb 11, 2004 at 06:31 UTC
    Without having benchmarked it, I have a feeling that your lookahead regex will fail faster if it's anchored:
    /^(?=.*a)(?=.*e)(?=.*i)(?=.*o)(?=.*u)/i
Re: Re: regex testing for ALL of the vowels in a scalar
by Roger (Parson) on Feb 11, 2004 at 05:59 UTC
    Yes, the look for a string containing this and that idiom ...
    /(?=.*?this)(?=.*?that)/

    Very nice.