RegexWars
Tier 2 · Archmagematch

Run Of Five

A hand is five cards as "2H 3S 4D 5C 6H" — rank then suit, space separated, and always sorted by rank, ascending. The rank ladder is A 2 3 4 5 6 7 8 9 T J Q K: the ace is low, so A-2-3-4-5 is a run and A-T-J-Q-K is not. Match a hand whose five ranks are consecutive on that ladder.

Regex cannot add one to a rank, so "consecutive" has to be spelled out — but you only ever need to spell out the twelve adjacent *pairs*, not the nine whole runs. Because the hand is sorted, a run is nothing more than four adjacent pairs in a row, and a lookahead lets you check a pair without consuming the card you are standing on.

Your pattern0 chars · par 74
//
Flags
Start typing — tests run as you go.0 of 6 visible tests passing
Test cases
  • 2H 3S 4D 5C 6Hmust match
  • AS 2H 3D 4C 5Smust match

    the wheel

  • 9H TD JS QC KHmust match
  • 2H 3S 4D 5C 7Hmust not match

    a gap at the top

  • 2H 2S 3D 4C 5Hmust not match

    a pair, not a run

  • AS TH JD QC KSmust not match

    the ace is low here, so this is not a run

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