Skip to content
DevMeme
Regex or Cat on Keyboard: The Eternal Question
Languages Post #81, on Feb 9, 2019 in TG

Regex or Cat on Keyboard: The Eternal Question

Why is this Languages meme funny?

Level 1: Secret Code or Scribbles?

Imagine a famous scientist fills a chalkboard with strange squiggles that supposedly mean something brilliant — and then a toddler grabs a chalk and scribbles all over the other half. Now ask a stranger which half is the genius part. They can't tell! The two muscly arms shaking hands are the scientist and the toddler agreeing: "our work looks exactly the same." That's the whole joke — programmers use a special symbol-language so messy-looking that even they can't always tell expert work apart from what happens when a cat marches across the keyboard.

Level 2: Decoding the Punctuation Soup

  • Regular expression (regex): a mini-language for describing text patterns. \d{3}-\d{4} means "three digits, a dash, four digits" — a phone number shape. Tools from grep to form validators run on them.
  • Why it looks like that: nearly every symbol is an operator. . means "any character," * means "zero or more," [] defines a character set, \ escapes things — so real patterns become dense thickets of brackets and slashes, exactly like the string on the handshake.
  • Write-only code: code that was easier to write than it will ever be to read. Regexes are the mascot.
  • Cat stepped on keyboard: the universal shorthand for random gibberish input — the null hypothesis your regex is being compared against.

The rite of passage: you'll write a glorious regex, it'll work, you'll feel like a wizard. Then a teammate will comment on your PR: "can you add a comment explaining this?" — and you will stare at your own creation, unable to comply. Welcome. There's a support group; it meets in the documentation nobody wrote.

Level 3: The Write-Only Language Pact

The Epic Handshake format — two heroically veined forearms from Predator locked in an arm-wrestle grip — exists to declare that two unlikely parties share common ground. Left bicep: REGULAR EXPRESSIONS. Right bicep: CAT STEPPED ON KEYBOARD. And spanning the clasped hands, their joint output:

[;'.']';'[\][I';:',\][(=)\=['':;'>>?{:>?":."?"

The joke's engine is indistinguishability. That string isn't a real regex — and that's the point. To a non-expert (and, honestly, to most experts at a glance), a battle-tested production pattern and feline percussion are the same genre of line noise. Regex is the canonical write-only language: its author, in a state of flow, compresses a paragraph of intent into thirty characters of punctuation; six months later that same author reads it back like an archaeologist who doesn't speak the dead language they personally invented. The famous Jamie Zawinski line — you have a problem, you use regex, now you have two problems — endures because the second problem is always the regex itself.

The deeper satire targets a real engineering trade-off: regexes optimize for density over legibility. Density wins at writing time (one line! so clever!) and loses at every subsequent moment of the code's life — review, debugging, modification, the 2 AM incident where someone must determine whether the email validator accepts a + sign. Teams accumulate folklore patterns nobody dares touch, copy-pasted from forum answers like cursed heirlooms. The remedies are known and underused: verbose mode with comments (re.VERBOSE), composing named sub-patterns, or admitting that a real parser was warranted three lookaheads ago. But the incentive structure rewards the handshake: the dense one-liner feels like mastery, and mastery that looks like a cat walked across your keyboard is, in this industry, a flex.

Level 4: Kleene's Algebra in a Cat's Pawprint

The cosmic irony this meme stumbles into: regular expressions are one of the most mathematically elegant objects in computer science, and they look like an accident. Stephen Kleene defined regular languages in the 1950s through an algebra of just three operations — concatenation, alternation (|), and the Kleene star (*) — and they sit at the bottom rung of the Chomsky hierarchy, precisely characterizing what a finite automaton can recognize. Kleene's theorem proves regexes, DFAs, and NFAs are exactly equivalent in power: every line-noise incantation is secretly a tidy state machine, derivable by Thompson's construction and minimizable to a canonical form. A true regular expression can be matched in $O(n)$ time with constant memory — the theory is beautiful.

The cat's revenge arrived in practice. Modern "regex" engines (PCRE, Java, Python's re) bolted on backreferences and lookarounds, features that push the formalism out of regular languages entirely — matching with backreferences is NP-hard — and most engines implement matching via backtracking search rather than automata. Hence catastrophic backtracking: a pattern like (a+)+$ against a long string of as explores exponentially many ways to partition the input, and your CPU melts. This is not academic — ReDoS via a single pathological regex in a user-agent parser once knocked Cloudflare's global edge offline for half an hour. So the meme's equivalence holds with embarrassing rigor: random paw input and a poorly-thought regex can both reduce to the same observable behavior — incomprehensible glyphs followed by an outage. The difference between Kleene algebra and a cat is the cat halts.

Description

The meme uses the 'Epic Handshake' format from the movie Predator, showing two muscular arms locked in a powerful handshake. The arm on the left is labeled 'REGULAR EXPRESSIONS', and the arm on the right is labeled 'CAT STEPPED ON KEYBOARD'. Above the clasped hands, representing the point of agreement, is a string of cryptic, jumbled characters: '[';]';\//][';‘\//[]-=\[';>>?{;>?'l;”?”'. This image humorously equates the notoriously dense and unreadable syntax of regular expressions (regex) with the random string of characters produced when a cat walks across a keyboard. The joke resonates with any developer who has faced the challenge of writing or deciphering a complex regex, highlighting that the end result often looks like meaningless gibberish to the uninitiated, and sometimes even to the person who wrote it

Comments

8
Anonymous ★ Top Pick The scary part is when you find a regex in production and you can't tell if it was written by the original senior dev or their cat
  1. Anonymous ★ Top Pick

    The scary part is when you find a regex in production and you can't tell if it was written by the original senior dev or their cat

  2. Anonymous

    Regex and housecats both prove that a simple nondeterministic finite automaton can generate strings no human should ever have to interpret in production reviews

  3. Anonymous

    The only difference between a production regex and a cat walking on your keyboard is that the cat's version has better documentation

  4. Anonymous

    The difference between a production regex and a cat on the keyboard is that the cat's version probably has fewer catastrophic backtracking issues

  5. Anonymous

    The real tragedy isn't that regex looks like a cat walked across your keyboard - it's that after 15 years of experience, you can actually parse that monstrosity in your head, understand it's checking for escaped backslashes in Windows file paths, and know exactly why it'll fail on edge cases. The cat's random output might actually be more maintainable

  6. Anonymous

    Regex and cats are both nondeterministic finite automata - cute until the backtracking goes exponential and your SLO evaporates

  7. Anonymous

    Regex: the only DSL where a keyboard smash compiles to a DFA, passes unit tests, and then pages SREs at 3am when greedy quantifiers meet user input

  8. Anonymous

    Cat regex: achieves catastrophic backtracking with zero lookahead assertions or committee reviews

Use J and K for navigation