2012-04-14 24 views
6

私は次の割り当てを持っています:正規表現の末尾にある「 2」は何ですか?

曲の単語は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はどういう意味理解していませんか?

+0

は、あなたがそれを試してみたことがありますか?この宿題ですか? – Toto

+0

階段が拒否されました:) – Robbie

答えて

11

逆参照です。 http://www.selectorweb.com/grep_tutorial.htmlから

前方参照は、式\ nは数です。これは、式中のn番目の括弧セットの内容に一致します。

また、その答えは、(d)は:

$ grep -E '(^.{4})(.{2}).*[ ]\2' test.txt 
If there's a bustle in your hedgerow. 
関連する問題