egrepオーダーが間違っています

egrepオーダーが間違っています

これはスクリプトの一部です。最初の単語に文字列が複数回あるか、最後の単語(最後の単語の1行)に複数回あるかを確認する部分。 。

echo "$first $last" | egrep "(([^ ]+)[^ ]* \1[^ ]* )[ ]* \2\2 * "

エラーは次のとおりです。

egrep: Invalid back reference

ベストアンサー1

表現を解く:

NODE                     EXPLANATION
--------------------------------------------------------------------------------
  (                        group and capture to \1:
--------------------------------------------------------------------------------
    (                        group and capture to \2:
--------------------------------------------------------------------------------
      [^ ]+                    any character except: ' ' (1 or more
                               times (matching the most amount
                               possible))
--------------------------------------------------------------------------------
    )                        end of \2
--------------------------------------------------------------------------------
    [^ ]*                    any character except: ' ' (0 or more
                             times (matching the most amount
                             possible))
--------------------------------------------------------------------------------
                             ' '
--------------------------------------------------------------------------------
    \1                       what was matched by capture \1
--------------------------------------------------------------------------------
    [^ ]*                    any character except: ' ' (0 or more
                             times (matching the most amount
                             possible))
--------------------------------------------------------------------------------
                             ' '
--------------------------------------------------------------------------------
  )                        end of \1
--------------------------------------------------------------------------------
  [ ]*                     any character of: ' ' (0 or more times
                           (matching the most amount possible))
--------------------------------------------------------------------------------
                           ' '
--------------------------------------------------------------------------------
  \2                       what was matched by capture \2
--------------------------------------------------------------------------------
  \2                       what was matched by capture \2
--------------------------------------------------------------------------------
   *                       ' ' (0 or more times (matching the most
                           amount possible))

\1キャプチャされたコンテンツの定義が完了する\1前に参照したいようです。

おすすめ記事