http://qs321.pair.com?node_id=944279


in reply to Re: regex to find vowels in anyorder
in thread regex to find vowels in anyorder

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.

Replies are listed 'Best First'.
Re^3: regex to find vowels in anyorder
by JavaFan (Canon) on Dec 19, 2011 at 17:58 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.
    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"
        You also asked (in a message, but the answer is way to lengthy for the peephole messages force you to use):
        Perhaps I fail to understand your question. My comment predicated on the fact that if a vowel is absent, continuation is moot. Not so?
        Let me explain the sequence of events:
        1. varghees asks the original question how to write a regexp matching all five vowels.
        2. SuicideJunkie gives the obvious answer, the "anded if".
        3. leuchuk replies to SuicideJunkie, saying he wouldn't use the "anded if" solution, but an array based on because 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.
        4. I ask leuchuk why he'd choose that solution over the "anded if", as the "anded if" also gives that benefit (you, know, short-circuiting logic operators) -- but leuchuk seems to suggest that it doesn't.
        5. You reply to me with If the first is not found, you're done, per OP's spec: "all 5 vowels". Noone in this sequence of posts leading up to yours has giving even the most remote inkling that he was thinking it was about anything else but matching all 5 vowels.
        So, let me repeat my question, how does your reply to me answer the question why doesn't an "anded if" stop if a vowel isn't found? It's not that what you say is wrong, it's just that you're stating something irrelevant as it doesn't even try to answer the question.
        If the first is not found, you're done, per OP's spec: "all 5 vowels"
        How does that answer my question?
Re^3: regex to find vowels in anyorder
by SuicideJunkie (Vicar) on Dec 20, 2011 at 00:17 UTC

    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.