Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: regex to find vowels in anyorder

by SuicideJunkie (Vicar)
on Dec 19, 2011 at 15:04 UTC ( [id://944255]=note: print w/replies, xml ) Need Help??


in reply to regex to find vowels in anyorder

Smells like homework.

The best way is likely to be KISS:

if (/a/ and /e/ and /i/ and /o/ and /u/ and (rand()>0.5 or /y/)) { ... }

Replies are listed 'Best First'.
Re^2: regex to find vowels in anyorder
by leuchuk (Novice) on Dec 19, 2011 at 16:55 UTC

    I wouldn't do this as an "anded if" but in a loop with an array of vowels. As soon as the script has found the first vowel the script would continue with the next vowel but if the vowel wasn't found it would stop the whole search as it's not interesting whether the other vowels are in the string.

    The performance of my solution depends on the distribution of the strings. Statistically I'm too weak to tell you what is faster. The longer your strings are the worse is my solution. If your search contains a lot of strings and there are some with a length less than number of vowels you could skip the whole test as in a less-than-five(six)-letter-string there is evidently no chance for five(six) different vowels.

      I wouldn't do this as an "anded if" but in a loop with an array of vowels. As soon as the script has found the first vowel the script would continue with the next vowel but if the vowel wasn't found it would stop the whole search as it's not interesting whether the other vowels are in the string.
      Uhm, in which way does an "anded if" continue with a next vowel after a previous vowel wasn't found?
        If the first is not found, you're done, per OP's spec: "all 5 vowels"

      As JavaFan and ww are discussing, your post seems to imply that you think the anded if does not short circuit when the first vowel is not found. That is not the case.

      A loop to put each vowel into regexes sequentially would have the advantage of not hardcoding the vowels, though it would do at least as much work.

Re^2: regex to find vowels in anyorder
by varghees (Novice) on Dec 19, 2011 at 15:10 UTC
    Not a homework. but this question raised when we were discussing about regex between perl developers... I am looking for one expression to find it.
      So, what code did the discussion between you Perl developers produce? What advantages are there to it? What disadvantages? If you are developers, you will surely have written code. If none of you developers has an idea, it surprises me that none of you developers has a question about perlre.

      Perhaps the 'Look-Around Assertions' section of perlre might be helpful. See specifically (?=pattern). I would think that a set of five of these would work.

      --MidLifeXis

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://944255]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2024-03-29 14:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found