def matchPreviousExpr(expr):
rep = Forward()<EOL>e2 = expr.copy()<EOL>rep << e2<EOL>def copyTokenToRepeater(s,l,t):<EOL><INDENT>matchTokens = _flatten(t.asList())<EOL>def mustMatchTheseTokens(s,l,t):<EOL><INDENT>theseTokens = _flatten(t.asList())<EOL>if  theseTokens != matchTokens:<EOL><INDENT>raise ParseException("<STR_LIT>",<NUM_LIT:0>,"<STR_LIT>")<EOL><DEDENT><DEDENT>rep.setParseAction( mustMatchTheseTokens, callDuringTry=True )<EOL><DEDENT>expr.addParseAction(copyTokenToRepeater, callDuringTry=True)<EOL>return rep<EOL>
Helper to define an expression that is indirectly defined from
       the tokens matched in a previous expression, that is, it looks
       for a 'repeat' of a previous expression.  For example::
           first = Word(nums)
           second = matchPreviousExpr(first)
           matchExpr = first + ":" + second
       will match C{"1:1"}, but not C{"1:2"}.  Because this matches by
       expressions, will *not* match the leading C{"1:1"} in C{"1:10"};
       the expressions are evaluated first, and then compared, so
       C{"1"} is compared with C{"10"}.
       Do *not* use with packrat parsing enabled.