5

How can I match a word containing every vowel at least once?

brian d foy
  • 129,424
  • 31
  • 207
  • 592

2 Answers2

4

It depends what you mean by a “vowel” — and for that matter, what you mean by “word”, too — but the normal way would be something like this:

(?xsi)
(?= .* a)
(?= .* e)
(?= .* i)
(?= .* o)
(?= .* u)
(?= .* y)

But you don’t want to do it that way. You want to put the logical conjunction in the programming language proper, not the regex, which leads to something like this (disregarding casing issues):

/a/ && /e/ && /i/ && /o/ && /u/ && /y/

What’s a Vowel?

Note that the entire “vowel” issue is pretty ridiculous, because any continuant can act like a vowel, even if it doesn’t look like one. That means that some letters that don’t look like vowels, are. Plus sometimes letters look like vowels but aren’t.

  1. For example, the s is psst, the second l in little, the r in acre, and the n in nth are all acting as vowels. Plus there’s the famous word cwm, from Welsh, where w is a vowel.

  2. Furthermore, the e in Mike is not acting as a vowel, whereas the i there is a diphthong (two vowels fused).

  3. Also, while the y in sky is a vowel, the y in yellow is not a vowel.

  4. You’ll have to figure out how many vowels you think there are in words like lie or speak, or even queue.

  5. Finally, if you have diacritics, you have to decide whether to count them as separate. Are e, é, è, and ê just one vowel, or four?

brian d foy
  • 129,424
  • 31
  • 207
  • 592
tchrist
  • 78,834
  • 30
  • 123
  • 180
  • I know it shouldn't be done with a regex, but I'm just curious. I can't get your first example working though ;o – John Connor Apr 25 '12 at 21:58
  • @JohnConnor Then run the first solution all together without spaces. You probably don’t have `/x` working. – tchrist Apr 25 '12 at 23:36
  • @tchrist What is `(?xsi)`? (JS complains it's not a valid group, fwiw.) – broofa Apr 28 '12 at 12:45
  • @broofa - Kindof shocking. I guess you could test it. Have you tired the individual characters? ie; `(?x)`,`(?s)`,`(?i)` ? Any of those types supported? –  Apr 30 '12 at 01:01
  • To answer my own question: See the 'modifiers' section of http://www.regular-expressions.info/refadv.html. @sin: Looks like JS (at least in Chrome) doesn't support modifier groups. – broofa Apr 30 '12 at 12:48
  • @broofa - Does it support the `/../mod` syntax? –  Apr 30 '12 at 23:53
2

How about this

\s* (?= \S* a)  (?= \S* e)  (?= \S* i)  (?= \S* o)  (?= \S* u)  (?= \S* y) (\S*)