我想找到一个正则表达式或 perl 单行代码来检测两行连续的行,这些行包含相同的单词且顺序相同,但前导空格、尾随空格和单词之间的空格数量可能因行而异。正则表达式必须排除那些不匹配的行。
我使用这个正则表达式来检测相同的连续行,
^\s*(.*\S)(\s\n*\1)+$
当一行与另一行之间的空格量不同时,它会失败。
我有这个示例文本
Mary has a little lamb. The live near the mountain.
Mary has a little lamb. The live near the mountain.
vrfgrgru hfiughf iujhfuihgifughuir nuhuvhfug
Mary has a little lamb. The live near the mountain.
Mary has a little lamb. The live near the mountain.
Mary has a little lamb. The live near the mountain.
Mary has a little lamb. The live near the mountain.
fghurhg bojghirejyohi ndhguhyituhgi
gbshbsiughsf bnighriugh hurhgiurhgriu
Elvis was the greatest singer of all time. He has 18 number one in billboard charts.
Elvis was the greatest singer of all time. He has 18 number one in billboard charts.
sgfuhgdugusd vfjsng orjgoergo ejfio dsmnjn
fbdhsbfgdbhhbfhdsfdf
Mary has a little lamb. The live near the mountain.
Mary has a little lamb. The live near the mountain.
gsete gerttrb oijoijoijoijoijoiojo gogoerijoi
jhoiyrei erogjrijgtrio noifdo mkooi
This has been the coldest winter in the last 20 years.
This has been the coldest winter in the last 20 years.
无论行中有多少个空格,正则表达式都应该显示包含相同信息的连续行。
没有三个连续的并且匹配的行之间没有空行。