A possible solution could be to use a positive look behind:
(?<=n)n
It would give you the end position of:
- *n***n**nn
- n*n***n**n
- nn*n***n**
As mentionned by Timothy Khouri, a positive lookahead is more intuitive
I would prefer to his proposition (?=nn)n
the simpler form:
(n)(?=(n))
That would reference the first position of the strings you want and would capture the second n in group(2).
That is so because:
- Any valid regular expression can be used inside the lookahead.
- If it contains capturing parentheses, the backreferences will be saved.
So group(1) and group(2) will capture whatever 'n' represents (even if it is a complicated regex).
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…