Steffan Harris
Steffan Harris

Reputation: 9326

Regex match ordering

My question is simple suppose I would like to match the vowels in a word, but I would like to match them in a specific order as the appear such as a, e, i, o, u. How would I go about doing this?

Upvotes: 4

Views: 17305

Answers (2)

sawa
sawa

Reputation: 168081

I would go with:

a.*?e.*?i.*?o.*?u

But this has the same problem that is pointed out in a comment by Alvin to Votley's answer. This is due to the question not specified enough. It is not specified what the priority is.

Upvotes: 0

VoteyDisciple
VoteyDisciple

Reputation: 37803

So you're looking for a followed by some characters, then e followed by some characters, and so forth?

In other words, a followed by stuff that isn't e, then e. Then stuff that isn't i then i. Then stuff that isn't o then o. And finally stuff that isn't u and lastly a u.

In regexp terms, that's a[^e]*e[^i]*i[^o]*o[^u]*u

(You could get by with a .*? but why do that when you can more precisely define what you mean.)

Upvotes: 10

Related Questions