Regular expression module malfunction?

I am working on bonus levels at regex golf and I am currently experiencing module issues. The regex engine used is "theoretically ECMAScript, but browser options vary, often by version." I do not know, from my point of view, what version of my browser (Firefox 34.0).

Basically, the idea is to match the expression of the form

x* % x+ = x*

where the number of repeating xrepresents numbers. The trick should only correspond to valid modulo actions.

My best solution so far is the following:

^(?=x+ % (x+) )\1*(x*) % x+ = \2$

That is, I use lookahead to get the number xin the second group, matching this pattern as many times as I can, and then I get a link back to the remainder, which should be the pattern on the right side.

Now, as far as possible, it works, but does not work (mistakenly mistakenly) in two specific cases:

xxxxx % xxxxx = xxxxx
xxxxxxxxxxxxxx % xxx = xxxxx

One of the great things about this particular regular expression game implementation is that it shows you the portion of the string that matches. Which is really interesting, if I unbind the end of line ( $), the consistent area for both goes from the beginning of the line to ^below:

xxxxx % xxxxx = xxxxx
               ^
xxxxxxxxxxxxxx % xxx = xxxxx
                        ^

, , - x, \2 . 2, \2 xx, . , .

:

xxxxxxxxxxxx % xx = x
xxxxx % xxx = xxxx

0 2 .

? ?


, . \1 FEWER, , \2, rhs. , , ... , ? .

+4
1

, $2 $1 x s.

: (https://regex101.com/r/oY1mV7/1)

^(?=x+ % (x+) )\1*(?!\1)(x*) % x+ = \2$

(https://regex101.com/r/oY1mV7/2)

\b(x*)\1*(?!\1)(x+) % \1\b = \2\b

- , JavaScript: (https://regex101.com/r/oY1mV7/3)

\b(x*)\1*+(x+) % \1\b = \2\b
+2

All Articles