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