适用于 egrep 的正则表达式,用于重复出现一对字符

Regular expression which is suitable for use with egrep for repeated occurence of pair of characters

需要打印仅包含一次笑声的行,其中笑声被定义为形式为哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈!的字符串,其中包含任意多个 ha。

我有的是

egrep "^Ha.*[ha*][!$]" myfile.txt

并打印

Hahahahahahahahahahahahahaha!
Hahahahahahahahahahahahahaha! nklddln

和myfile.txt包含

kaka
linux.student.cs.uwaterloo.ca
So How is going on Man. 
I am now just trying to test the stuff with Ubuntu
Digit in the line 1
Regular<title> expression</title> stuff must be working
alright just testing linux.studEnt.cs.Uwaterloo.ca
liNUx.student.cs.uwaterlOO.Ca so the things
We need to</title> have more thn ten<title> lines that have more tha twenty characters
So, the assignment needs to be done very quickly
This cs247 line contains the course code cs246
The course code cs246 is in the cs247 line
All these lines in this text file are for testing only
We need to<title></title> thouroughly check the cs246 assignment
heheheheehe man this work will take some time
you have to be quick as we need to get it done before deadline
Okey kaka g whats the situation
Man How are you?
course code is CS246
course CS246
Hahahahahahahahahahahahahaha!
ghjf akf Hahahahahahahahahahahahahaha!
dhgD Hahahahahahahahahahahahahaha! jwef
Hahahahahahahahahahahahahaha! nklddln
hufwf Hahahahahahahahahahahahahaha!
course cs246
12345678901234567890
1234567890123456789

我不想打印第二行,因为它包含一个额外的词。必须使用egrep。

需要在!之后使用anchor$进行精准匹配:

egrep '^Ha(ha)+!$' file

Hahahahahahahahahahahahahaha!