我有以下任务:
歌曲的歌词在名为 stairway.txt 的文件中。此命令后将打印出以下哪一行:
grep -E '(^.{4})(.{2}).*[ ]\2' stairway.txt
(a) Yes, there are two paths you can go by but in the long run
(b) Its just a spring clean for the May queen.
(c) Don't be alarmed now.
(d) If there's a bustle in your hedgerow.
(e) Theres still time to change the road you're on.
不明白最后的\2
是什么意思?
最佳答案
这是一个反向引用。
来自 http://www.selectorweb.com/grep_tutorial.html :
Backreference is an expression \n where n is a number. It matches the contents of the n'th set of parentheses in the expression.
另外,答案是(d):
$ grep -E '(^.{4})(.{2}).*[ ]\2' test.txt
If there's a bustle in your hedgerow.
关于regex - 正则表达式末尾的 "\2"是什么意思,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10152512/