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


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

I think BrowserUk's solution is going to be faster. But past that I would not use nested if's when you mean "and" or "&&". Get rid of 4 unnecessary levels of indentation.

Replies are listed 'Best First'.
Re^3: regex to find vowels in anyorder
by JavaFan (Canon) on Dec 19, 2011 at 18:06 UTC
    I think BrowserUk's solution is going to be faster.
    That would not be my guess, unless it's the /i that's killing the performance. /a/ will not use the regexp engine, the optimizer will do it. If speed is an issue, and you want to be case sensitive, my bet would go to:
    if ((/a/ || /A/) && (/e/ || /E/) && (/i/ || /I/) && (/o/ || /O/) && (/ +u/ || /U/)) { ... }
    but I'm too lazy to come up with a good benchmark (which should test for both match and non-match). And if the query set would be English words, I'd order the vowels from least frequently occurring to most frequently (probably u-i-o-a-e, but I'd have to look that up), in order to fail faster.

    Of course, it's also very likely speed doesn't matter at all.