RegexWars
Tier 4 · Enchantercapture

Pawn Check Squares

A white pawn checks the black king from the square down-left or down-right of it. Capture both squares.

The whole board is one line. Squares run row-major from the top-left, an empty one is a dot, and between rows sit seven # — one fewer than the board is wide — so a diagonal or a knight jump that runs off the side lands on padding instead of wrapping onto the next rank. The black king is k; white pieces are uppercase P N B R Q K. The first row is rank 8, so white advances towards the start of the string. One square right is +1 and one square down is +15; every other offset you need is built from those two. Capture group 1 is the down-left square and group 2 the down-right one. Where a square is off the side of the board you will capture a # instead — that is the padding earning its keep. The rule at the edges is about the string, not the rank: if either square would fall past the end of it there is nothing to capture, so the pattern must not match at all. That is every king on the last row, and also a king on the very last file of the second-to-last row — which is the one place this challenge and real chess disagree, because there the pawn check is real but the square that would show it does not exist.

Your pattern0 chars · par 13
//
Flags
Start typing — tests run as you go.0 of 5 visible tests passing
Test cases

Wrapped into rows of 8 so you can see the board. The string itself is one line with no line breaks in it — the 7 # between rows are ordinary characters, and a dot will happily match straight past them.

  • ........#######
    ....k...#######
    ...P....#######
    ........#######
    .....N..#######
    ........#######
    ........#######
    ...K....
    → ["P", "."]

    a pawn down-left is giving check

  • ........#######
    ........#######
    ........#######
    ..k.....#######
    ...P....#######
    ........#######
    .....B..#######
    ........
    → [".", "P"]

    and down-right

  • ........#######
    ........#######
    ....k...#######
    ....P...#######
    ........#######
    ..N.....#######
    ........#######
    ........
    → [".", "."]

    a pawn straight ahead attacks neither square

  • ........#######
    ........#######
    k.......#######
    .P......#######
    ........#######
    ........#######
    ....R...#######
    ........
    → ["#", "P"]

    off the a-file there is only padding

  • ........#######
    ........#######
    ........#######
    ........#######
    ........#######
    ..B.....#######
    ........#######
    ...k....
    must not match

    nothing below the last row

+ 3 hidden tests, checked when you submit. They are what stops a pattern that only fits the examples above.