Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

regex for one character or another?

Tags:

regex

grep

I'm searching for a regex code which lists all the lines that contain an a OR an i. I tryed this:

grep -E '[(a|i)]{1}' testFile.txt

but this gives me the words containing a or i and words that contain a en i. What's wrong?

like image 261
user2810895 Avatar asked Oct 03 '13 12:10

user2810895


1 Answers

You can achieve that with:

grep -E "^[^ai]*(a|i){1}[^ai]*$" testFile.txt
like image 153
Alma Do Avatar answered Sep 20 '22 20:09

Alma Do