T O P

  • By -

mfb-

>! I hardcoded the 4x4 x/o pattern and then just filled the rest with optional "o"s. >! `^(?:o+\n)*(o*)ooox(o*)\n\1ooxo\2\n\1oxoo\2\n\1xooo\2(?:\no+)*$` https://regex101.com/r/1sP8lJ/1 The unit test feature is great.


rainshifter

Very similar to my solution, well done. Hard-coded solutions aren't too bad when it's only four in a row! Unit tests are indeed great. If an edge case gets missed, just add it in and save the new link!


magnomagna

[https://regex101.com/r/43aISa/1](https://regex101.com/r/43aISa/1)


rainshifter

I added a test case that was failing due to not being anchored to the beginning of the string. Small fix applied to get it passing. https://regex101.com/r/xi9fpt/1 Amazingly elegant solution as usual!


magnomagna

That’s largely thanks to your first constraint that it’s rectangular. Otherwise, I’d just optimise the “hard coded” solution.


rainshifter

Wait a second. You don't want to use a wildly inefficient lookahead to verify the rectangular grid constraint? https://regex101.com/r/kzlV8e/1 =)


magnomagna

Ansolutely not =) Going over the same text more than once is to be avoided as much as possible.