Actually I'm beginner in regex. I managed to do the following:

egrep '[aeiou]\b' - the last character for each word is a vowel

egrep '^[^ ]+' - first word of line

But I have no idea how to write regex to match my task. I will be very grateful if you could help me.

You may match the start of a line with ^, then match any amount of letters using [[:alpha:]]* and then match the vowel with [aeiuo] and then assert a trailing word boundary (\b or \>):

grep  '^[[:alpha:]]*[aeiou]\b'
grep  '^[[:alpha:]]*[aeiou]\>'

Tested in Ubuntu:

enter image description here

  • To complicate things, this can be a better (pc)re: (?i)(?<=^\s*)[a-z]*[aeiou]\b. Needs support for variable-length lookbehinds, though. – iBug Sep 16 at 15:31
  • 1
    Well, if you put it that way, there is no need in a lookbehind, grep -iP '^\s*\p{L}*[aeiou]\b' and grep -P '(?i)^\s*\p{L}*[aeiou]\b' work, too. – Wiktor Stribiżew Sep 16 at 15:33

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.