0

I'm starting the study of regular expressions and I've been wondering how can I build and test the regular expression in UNIX notation for all vowel strings that contain the substring "ai" or "ui".

would it simply be something like: (ai|ui) ? How could I test it?

1 Answers1

1

IIUC, you want something like '^[aeiou]*?(ai|ui)[aeiou]*$'. Examples:

$ echo aaauiaa | grep -E '^[aeiou]*?(ai|ui)[aeiou]*$'
aaauiaa
$ echo aaaaiaa | grep -E '^[aeiou]*?(ai|ui)[aeiou]*$'
aaaaiaa
Arkadiusz Drabczyk
  • 11,227
  • 2
  • 25
  • 38
  • When I test this expression on https://www.regexpal.com/ it doesn't select the vowel strings that contain the substring "ai" or "ui. Shouldn't it work there, but anyway it was a bit more clear for me now – Lucas Brodersen Dec 06 '20 at 12:13
  • Do not put single quotes, they are only needed by shell. Try `^[aeiou]*?(ai|ui)[aeiou]*$` – Arkadiusz Drabczyk Dec 06 '20 at 12:53
  • If you like this answer please mark it as solved to let other users know your problem is solved. Also see [What should I do when someone answers my question?](https://stackoverflow.com/help/someone-answers) – Arkadiusz Drabczyk Dec 06 '20 at 14:46