0

I am making a simple regular expression to recognise first consonant(if any),then all the vowels in between and then the next consonant after the last vowel(if any).

For ex:

we are all morons -->> we ae al moon

I wrote this expression but it doesn't work in all situations.

Please advise.

"[^aeiou]?[aeiou]+[aeiou]?"

Not sure where I am getting wrong.

durron597
  • 30,764
  • 16
  • 92
  • 150
SteveIrwin
  • 115
  • 2
  • 14
  • Recognize? You want to capture them? In that case use capturing groups `()`. Also instead of writing `[^aeiou]` you should list all consonants because the negated vowels match other things than letters as well. (And what that leading `?` is doing there I don't know.) – Qtax Dec 02 '11 at 13:32

1 Answers1

1

You need to use non capturing groups so the matching wont halt. Now you are matching only words that matches your desired output. see : What is a non-capturing group? What does a question mark followed by a colon (?:) mean? for more information.

Community
  • 1
  • 1
Sonia
  • 934
  • 2
  • 11
  • 22