Valentyn
Valentyn

Reputation: 612

How to return lines, where the last word ending with a consonant letter?

My regex should return lines, where the last word ending with a consonant letter. I write:

egrep '[^aeiou]\b$'

but it returns only lines, which not ending in a dot.

I'm a beginner in regex, so I will be grateful if you could help me.

For example, my test file:

Hello world
Hello world.
London is the capital of GB.
Oslo is the capital of Norway
Oslo is the capital of Norway.
Oslo is not a capital of Ukraine.

Now my expression returns:

Hello world
Oslo is the capital of Norway

But it should return:

Hello world
Hello world.
London is the capital of GB.
Oslo is the capital of Norway
Oslo is the capital of Norway.

Upvotes: 1

Views: 83

Answers (1)

revo
revo

Reputation: 48751

The problem with your regex is that it looks for a letter that is not a vowel but in other side it doesn't necessarily looks for consonants. The \b shouldn't be there too. As You want to ignore punctuation marks try the following:

egrep '[b-df-hj-np-tv-z]\W*$'

\W means a character that is not [a-zA-Z0-9_]

Upvotes: 3

Related Questions