Using -P
option (PCRE) if available on your system:
grep -P '^(?=[a-zA-Z]{7}$)(.)(?!\1)(.)(?!\1)(?!\2)(.)\2(?!\1)(?!\2)(?!\3).\2\1$' inputfile
Explanation:
^
(?=[a-zA-Z]{7}$) : positive lookahead, zero-length assertion that make sure we have exactly 7 letters. You may use \pL{7} if you want to deal with any laguage
(.) : first letter, captured in group 1
(?!\1) : negative lookahead, zero-length assertion that make sure we don't have the same letter as in group 1 after
(.) : second letter, captured in group 2
(?!\1) : negative lookahead, zero-length assertion that make sure we don't have the same letter as in group 1 after
(?!\2) : negative lookahead, zero-length assertion that make sure we don't have the same letter as in group 2 after
(.) : third letter, captured in group 3
\2 : fourth letter == second letter
(?!\1) : negative lookahead, zero-length assertion that make sure we don't have the same letter as in group 1 after
(?!\2) : negative lookahead, zero-length assertion that make sure we don't have the same letter as in group 2 after
(?!\3) : negative lookahead, zero-length assertion that make sure we don't have the same letter as in group 3 after
. : fifth letter
\2 : sixth letter == second letter
\1 : seventh letter == first letter
$
DEMO
grep -E
or to escape parentheses. This should get rid of the backreference error, you will be able to continue now. Why are you asking about (partially) the same issue? Don't the solutions to the other question work on Mac? If they don't, the right thing to do is to give feedback to users who tried to help you there and solve the other question first, instead of raising the same issue for the second time. – Kamil Maciorowski Oct 15 '18 at 5:10