RegexWars
Tier 3 · Warlockmatch

Touching A Mine

A 5x5 Minesweeper grid with one square marked ?. Match it only when that square has a mine in one of its eight neighbours.

Rows flattened top-left first: * is a mine, . is clear, ? is the square you are asking about, and 4 hash characters separate one row from the next — one fewer than the width. Eight neighbours, but only four distances, because each one works from either side: 1 apart is left or right, 8 is up-right or down-left, 9 is straight up or down, 10 is up-left or down-right. Which means one contiguous range covers three of them. The padding is doing real work here — without it, the last square of a row would count as touching the first square of the next one.

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

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

  • .....####
    ..?*.####
    .....####
    .....####
    .....
    must match

    mine immediately right

  • *....####
    .?...####
    .....####
    .....####
    .....
    must match

    mine up-left

  • .....####
    .....####
    ..*..####
    ..?..####
    .....
    must match

    mine directly above

  • *....####
    .....####
    ..?..####
    .....####
    ....*
    must not match

    two mines, both far away

  • .....####
    ....*####
    ?....####
    .....####
    .....
    must not match

    end of one row is not next to the start of the next

  • .....####
    .....####
    ..?..####
    .....####
    .....
    must not match

    no mines at all

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