RegexWars
Tier 4 · Enchantercapture

Four In A Row

A Connect Four board, 7 wide and 6 tall, arrives as one flat string. Capture the colour — R or Y — that has four in a row horizontally. Capture nothing if neither has.

Rows are flattened top-left first, . for an empty slot, with 6 hash characters between one row and the next — one fewer than the width. Horizontally is the easy direction: the padding guarantees a run of four can never straddle two rows, so you are looking for four identical neighbours and nothing more. Only horizontal counts here; a column of four is somebody else's problem. Capture the colour once — group 1 is the winner.

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

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

  • .......######
    .......######
    .......######
    .......######
    ..Y.Y..######
    .RRRRY.
    → ["R"]

    red, along the bottom

  • .......######
    .......######
    .......######
    ..R....######
    .YYYY..######
    .RRYRR.
    → ["Y"]
  • .......######
    .......######
    ..R....######
    ..R.Y..######
    ..RYY..######
    .YRYRR.
    must not match

    red has four, but stacked — not horizontal

  • .......######
    .......######
    .......######
    .......######
    ...Y...######
    ..RYR..
    must not match
  • .......######
    .......######
    .......######
    .......######
    .......######
    .......
    must not match

    nobody has played

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