# Match correct multiplication statements in the domain ^x*\*x*=x*$ using only the ECMAScript subset of regex functionality # A = first factor; B = second factor; P = number we're testing as the potential product of A and B ^ (?= (x?(x*)). # \1 = A; \2 = A-1, or 0 if A==0; (x?(x*)) # \3 = B; \4 = B-1, or 0 if B==0 ) .*= (?= .* ( # \5 = A * B (?=\1*$) (?=\3*$) (?=\1\4+$) \3\2+$ | $\1 | $\3 ) ) \5$