Valentyn
Valentyn

Reputation: 612

Regex to extract a line in which the first word ends in a vowel

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.

Upvotes: 1

Views: 339

Answers (1)

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 627087

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

Upvotes: 3

Related Questions