RegexWars
Tier 2 · Archmageextract

Bishop Check

Extract every white bishop that is giving check along a diagonal, in board order.

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. One square down-left is +14 and one down-right is +16, so a diagonal is a chain of one of those steps with every square along the way empty — the first piece on the ray blocks everything behind it. The sting is the mode: extract compares the matched text, so the match has to be the B itself, which means all that geometry has to sit inside a lookahead or a lookbehind. Needs the g flag. A board with no checking bishop simply yields nothing.

Your pattern1 chars · par 87
//g
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.....#######
    ........#######
    ....B...#######
    ........#######
    ........#######
    ........
    → ["B"]

    down-right of the king

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

    up-left of the king

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

    a pawn blocks the diagonal

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

    checked from both ends

  • ........#######
    ........#######
    ........#######
    ...k..B.#######
    ........#######
    ........#######
    ........#######
    ........
    → []

    same rank, not a diagonal

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