egrep 顺序错误

egrep 顺序错误

这是脚本的一部分;这部分应该检查第一个单词中是否有一个字符串两次或两次以上,并且最后一个单词中是否存在两次或多次(在最后一个单词的一行中)。

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完成之前进行引用。

相关内容