Skip to content
DevMeme
529 of 7435
A Simple Two-Step Guide to Writing Regex
CS Fundamentals Post #609, on Aug 24, 2019 in TG

A Simple Two-Step Guide to Writing Regex

Why is this CS Fundamentals meme funny?

Level 1: Cat Wrote Your Code

Imagine you have a really complicated rule for something – say, a rule for what counts as a "good" username in a game. But the rule is written in a secret code that looks like gibberish. The joke here is that the rule is so confusing, it might as well have been typed by a cat walking across the keyboard. 🐱⌨️ In the cartoon, a dinosaur (the teacher) says to just let the cat play on the keyboard to create this super complicated pattern. Of course, that’s silly – cats can’t actually write code! But it’s funny because it feels true that the result (a regex pattern full of symbols) looks random, just like something a cat would type. The humor comes from exaggerating how unreadable these patterns are. It’s like if you asked an expert how to write an extremely hard puzzle and he jokingly replied, "Eh, just smash the pieces together and send it out." We laugh because sometimes in real life, experts do hand us solutions that look confusing, and we wonder, "Did someone’s pet come up with this?" In short, the meme makes us picture a cat creating a jumbled mess that somehow works as a solution – a playful way to say, "Wow, this code is so jumbled, even a cat could have written it!" It’s funny and comforting, because it shows even the pros find some code as bewildering as random kitty typing.

Level 2: Cat on Keyboard Regex

Let’s break down what’s happening in this meme in simpler terms. The joke is about regular expressions, often abbreviated as regex. A regular expression is like a little formula or pattern that programmers use to search or match text. For example, if you want to verify that a username contains only letters, numbers, and certain symbols, you might use a regex pattern to define that rule. Regex patterns, however, are written in a very condensed, symbolic syntax that can be hard to read. They include a lot of special characters with specific meanings.

In the meme, the text "HOW TO REGEX" sets up the idea that we’re getting a tutorial on using regex. The dinosaur character in business attire is presumably the teacher (and the caption calls him a "senior engineer"). In STEP 1, he says: "Open your favorite editor." That just means open up whatever program you write code in – a straightforward, no-nonsense first step for any coding tutorial. STEP 2 is where things go off the rails: "Let your cat play on your keyboard." We see a cute purple cat sitting on the laptop, presumably stomping on keys. Above the laptop floats a stream of what looks like random characters:

/^([A-Z0-9._\-…

That string of characters is meant to resemble a regex. Let’s decode a bit of it:

  • / – In many programming languages (like JavaScript), regex patterns are written between slashes. So the first "/" just marks the start of the pattern. (The closing "/" isn’t visible in the meme, but would be at the end of the pattern.)
  • ^ – This caret symbol means "start of string". It tells the regex engine, "the text must begin here". So ^A would mean "the string starts with an 'A'".
  • ( – Parentheses begin a group. Groups are used for grouping parts of patterns or for capturing substrings. Here we see an open parenthesis but not the close ), likely because the pattern continues beyond what’s shown.
  • [A-Z0-9._-] – This is a character class defined by the brackets. It means "allow any one character that is either an uppercase letter (A-Z), a digit (0-9), a dot (.), an underscore (_), or a hyphen (-)". Essentially, it's listing out allowed characters. If you put a set of characters inside [...], regex will match one character that is any of those in the list.
  • After that, there’s likely a quantifier like + (though the meme trails off with an ellipsis). If it were +, it means "one or more of the preceding item". So [A-Z0-9._-]+ would match a sequence of allowed characters (at least one character, and potentially many in a row).
  • We also see a **\** before the hyphen in the class ._\-. In regex syntax, some characters like - or . have special meanings. A backslash \ is used to "escape" them, meaning "treat this character as literal". The hyphen - inside a character class can indicate a range (like A-Z means all letters from A to Z). To include a literal hyphen, it’s often escaped as \- so it’s not mistaken for a range. Similarly, the dot . normally means "any character" in regex, but inside a character class it’s usually taken literally (though escaping it doesn’t hurt). So ._\- is ensuring the dot and hyphen are treated as regular characters to be matched, not regex wildcards.

So, believe it or not, the cat’s keyboard smash is actually forming the start of a legit regex that says: "string must start with a sequence of uppercase letters, digits, periods, underscores, or hyphens..." (and presumably it would end with $ meaning end of string). This kind of pattern is super common in programming for things like validating usernames, file names, IDs, etc. The humor is that even though this regex has a real purpose, it looks like gibberish. To an untrained eye (and often even to a trained one), /^([A-Z0-9._\-]+$/ isn’t immediately readable. It's not obvious that it means "only allow certain characters." It just looks like a cat walked across the keyboard and hit a bunch of random symbols! 😹

Now, "give keyboard to cat, ship to prod" is phrased in a way that pokes fun at developer culture. "Ship to prod" means deploying code to the production environment (where real users interact with the software). It suggests that this ridiculously generated regex is going straight into the final product without further ado. Of course, in reality, no responsible engineer would literally let an animal write code. The meme is satire. It's pointing out how writing a regex can feel like a random process because the end result often looks nonsensical anyway. If you've ever been a junior dev asking a senior dev for help with a tricky regex, you might have observed them trying a few different patterns, adding and removing characters, testing each attempt... it can look pretty haphazard. The senior dev might even joke, "ugh, this is basically voodoo" – essentially admitting that even they find it a bit trial-and-error. So the cat scenario is a humorous exaggeration of that trial-and-error process.

Let’s also consider why regex tends to be a shared pain in development:

  • Learning curve: Regex has a steep learning curve. The syntax is dense. Beginners often say it looks like random punctuation. It kind of does! For example, \d means any digit, \w means any word character (letters, numbers, underscore), * means "repeat 0 or more times". There are dozens of these little symbols and rules. So initially, it feels like learning Morse code or hieroglyphs.
  • Readability: Unlike writing normal code (which you can often make descriptive with clear variable names and comments), a regex is usually one big string of symbols. You can’t have spaces or line breaks (unless you use regex extended mode with special flags) because spaces are significant in patterns. So it’s inherently hard to make a regex look clean. Some people comment their regex or break it into multiple lines (with the x flag in some languages), but many don't bother, especially for one-off uses. The result: regex patterns in code often come without explanation, sitting there like a magical incantation.
  • Maintenance: If something changes (say the requirements for what counts as a valid username expand), modifying an existing big regex is tricky. There’s a real risk of breaking it in subtle ways. Because of that, developers sometimes avoid touching a working regex. They might layer another check around it in code rather than alter the regex itself. It becomes this fragile artifact in the codebase.

All these factors contribute to the joke. It’s a form of DeveloperFrustration humor. We’re laughing at our own difficulties with regex. The cat is a stand-in for the randomness and frustration we feel. The RelatableDevExperience here is that everyone in software has at least one memory of wrestling with a perplexing regex. Maybe it was parsing a complicated log file line, or validating email addresses (which, by the way, have infamously complex regex patterns if you try to cover every valid address). At some point you throw your hands up and think, "I might as well just smack the keyboard and see if that works."

Finally, notice that the meme is labeled under Languages and CodeQuality. Regex isn’t a full-fledged programming language in the same sense as Python or Java, but it is a language for patterns. And it’s part of many programming languages as a built-in tool or library. The code quality aspect comes from the fact that a regex like this, while powerful, scores low on readability – a key aspect of quality. Typically, good code is easy to read and understand. A gnarly regex is the opposite of that, yet we still use them because they solve problems efficiently. This meme playfully points out that tension: the practical power vs. the ugly form of regex. It’s like having a super useful gadget that unfortunately communicates in complete gibberish. So you use it, but you’re not exactly proud of how messy it looks. The senior engineer’s "tutorial" is him jokingly embracing the mess: "Step aside, junior, this is how we do regex – just let randomness happen and roll with it." The fact we find this funny means we all recognize there’s a grain of truth in it.

Level 3: Now You Have 2 Problems

There's a well-worn joke among developers: "Some people, when confronted with a problem, think: 'I know, I'll use regular expressions.' Now they have two problems." 🔥 This meme perfectly captures that sentiment. The senior engineer in the cartoon isn’t really teaching best practices – he’s sarcastically demonstrating how writing a regex feels. RegularExpressions are notoriously dense and hard to read, so the humor is that a random jumble from a cat can look indistinguishable from a production regex we might find in a legacy codebase. Seasoned developers are chuckling (or groaning) because we've all been there: inheriting a monstrous 300-character regex that validates, say, emails or phone numbers, and thinking "Did someone’s cat actually write this?"

The first panel's straight-faced instruction ("Open your favorite editor") lulls you into expecting a real tutorial. Then the second panel drops the punchline: "Let your cat play on your keyboard." The dinosaur character’s deadpan expression sells it – he’s the picture of a jaded senior engineer who has seen one too many unmaintainable regexes in his time. This absurd "tutorial" is a wink to every developer who's struggled with code quality when regexes are involved. We treat regex creation half like an arcane art. Honestly, sometimes crafting a complex pattern feels like randomly hitting keys until “/^(?!.(?:))…”* appears and miraculously works. The meme exaggerates that feeling to hilarious effect.

Why is this so relatable? Because developer humor often springs from shared pain. And regex maintenance nightmares are almost universal in programming. In real life, using regex can be a double-edged sword: it's incredibly powerful for text processing, but the resulting pattern can be almost unreadable to the human eye. Ever open a code file to find a regex that looks like ^(?=.{8,20}$)(?=(?:.*\d){2})(?=(?:.*[A-Z]){2}).* and immediately feel a headache coming on? It’s like deciphering ancient hieroglyphs. Many of us have resorted to "YOLO" approaches: copying a regex from Stack Overflow or a blog, tweaking one or two characters, and hoping we don’t break anything — because fully understanding it might take all afternoon. The meme pokes fun at this by implying even a cat could smash out the needed symbols, since there’s almost an element of chance in getting a complex regex right.

The phrase "ship to prod" in the title ("give keyboard to cat, ship to prod") adds another layer of senior-engineer cynicism. It implies deploying code to the production environment without rigorous review. In a well-run project, any code (especially something as critical and potentially risky as a regex) should be carefully tested and reviewed. But let's be real: when a deadline looms or a critical bug needs a quick fix, even senior devs sometimes write a quick-and-dirty regex, see it passing a few tests, and push it to production with a silent prayer. The meme exaggerates this by removing the human effort altogether – just let the cat mash keys, good enough, deploy it. It’s funny because it satirizes a real anti-pattern in software development: sacrificing clarity and maintainability for speed or convenience, then shipping the result.

The dinosaur in a tie (looking suspiciously unamused) represents that seasoned engineer mindset: slightly sarcastic, battle-scarred from countless late-night debugging sessions involving regex. If you look closely at panel 2, the "regex" floating above the laptop /^([A-Z0-9._\-… isn’t pure gibberish – it actually resembles real patterns we’ve seen in the wild. Something like ^([A-Z0-9._-]+)$ would be a very common regex to allow only certain characters (uppercase letters, digits, dot, underscore, hyphen). The punchline is that such a pattern, while meaningful, looks random to someone reading it fresh. We laugh (a bit nervously) because maintaining such code feels like trying to edit a novel written in Martian language.

From a CodeQuality perspective, the meme highlights a genuine issue: regex patterns are write-only code. That is, a developer writes them once, and thereafter everyone is afraid to touch them. The joke "cat-written" regex is the ultimate write-only code – nobody, not even the author (or the cat 🐱), can truly read it afterwards. Have you ever had a team discussion about refactoring a giant regex? It often ends with "Let's just leave it; it works." We joke that we'll document it or clean it up next sprint someday, but that day rarely comes. This shared reluctance is exactly why the meme is so Relatable: every dev team has that one regex buried in the code that all the new hires get warned about. ("See that line? Don’t touch it, don’t even look at it funny. We don’t fully know what it does, but if it breaks, everyone will have a bad day.")

The humor also reflects how even experienced engineers can feel frustration with regex. Being "senior" doesn’t magically make regex readable; it just means you’ve battled them before. The senior engineer character here isn’t really advocating bad practice – he’s acknowledging, with dark humor, that writing a complex regex can devolve into madness. "We might as well have the cat do it, it won't be any less comprehensible." It’s a form of collective catharsis, turning our regex struggles into a joke that we can all nod and laugh at. After all, when confronted with the alternative (crying over a 1000-character pattern), laughing is the healthier option.

Level 4: Irregular Expressions

At the most theoretical level, this meme touches on the chaos and complexity inherent in regular expressions (regex) by joking that a cat on a keyboard could produce one. Ironically, regex are grounded in elegant formal language theory: they correspond to regular languages that can be recognized by finite automata. In theory, every cryptic regex pattern represents a well-defined state machine. In practice, though, complex regex patterns often look like digital hieroglyphics. The string floating above the laptop in the second panel, for example, starts with ^([A-Z0-9._\-…. To a theoretician, symbols like ^, [A-Z0-9._-], etc., are part of a precise grammar that can be parsed into an abstract syntax tree defining a language. To a weary developer at 3 AM, that same string might as well be the cat walking on the keyboard.

From a computer science perspective, regex syntax was designed to be compact rather than readable. It uses punctuation symbols as operators: * (the Kleene star) means "repeat zero or more times," | means "or", parentheses group patterns, [] defines character classes, and so on. The goal was brevity and formal power, not human-friendly syntax. This is why a line of regex can pack a ton of logic into a few characters, but also why it resembles line noise (random modem gibberish) to the untrained eye. In fact, there's a classic joke that complex regex patterns look like comic-book swearing – all those symbols @$%^& might as well be a cartoon "#&@!". The meme exaggerates that idea: the "tutorial" suggests literally generating the pattern via keyboard mashing (with feline assistance). The humor works because regexes do often appear as if they were generated by chaotic banging rather than careful typing.

What makes this especially funny for seasoned devs is the kernel of truth behind the absurdity. Over the years, regex engines have evolved beyond the original theoretical regex (which were truly "regular" in the formal sense) to include advanced features like backreferences and lookahead assertions. These additions give regex more power (technically some modern "regex" can recognize non-regular languages), but at a cost: increased complexity in both readability and execution. A randomly hammered-out pattern could inadvertently include a catastrophic backtracking situation or an ambiguous sub-pattern that even the regex engine struggles with. Essentially, as regex grew more capable, they also became easier to misuse or abuse. A cat on the keyboard might stumble upon a syntactically valid pattern (regex syntax is quite permissive), but that pattern could be riddled with edge-case pitfalls that only a formal analysis (or painful production bug) would uncover.

This deep-dive angle also touches on the idea of emergent complexity. A regex like the one hinted in the image (/^([A-Z0-9._\-…) is small in length but potentially huge in behavior – it defines an entire set of strings via a terse expression. It’s a bit like a DNA sequence coding for a complex organism: inscrutable sequence, complex outcome. The senior engineer’s tongue-in-cheek "give the keyboard to the cat" method winks at the truth that writing a correct, comprehensive regex often feels like random trial-and-error. Formally, you could design a regex by carefully constructing a deterministic finite automaton or drawing syntax diagrams. But in reality, many of us just slam out patterns and tweak them until tests pass – a process not so far removed from letting a pet walk on keys and seeing what happens. The meme uses that absurdity to highlight how counterintuitive and impenetrable regexes can be, despite their rigorous theoretical underpinnings. In short, what’s regular in theory often becomes irregular in practice, and the cat-on-keyboard method is a satirical jab at that disconnect.

Description

A two-panel comic strip by artist @GARABATOKID titled 'HOW TO REGEX'. The comic features a green dinosaur character in a light blue shirt and red tie. In the first panel, captioned 'STEP 1: OPEN YOUR FAVORITE EDITOR', the dinosaur points to a laptop displaying an empty code editor. In the second panel, captioned 'STEP 2: LET YOUR CAT PLAY ON YOUR KEYBOARD', the dinosaur dangles a cat toy over the laptop's keyboard, where a purple cat is now pawing at the keys. The laptop screen now shows a string of characters typical of a regular expression: '/^([A-Z0-9_\.\-'. The humor is a commentary on the notoriously cryptic and seemingly random syntax of regular expressions, suggesting that their complexity makes them look as if they were generated by a cat walking across a keyboard rather than being written by a human

Comments

7
Anonymous ★ Top Pick The main difference between writing regex and performing an arcane ritual is that with the ritual, you at least have a vague idea of what demon you're summoning
  1. Anonymous ★ Top Pick

    The main difference between writing regex and performing an arcane ritual is that with the ritual, you at least have a vague idea of what demon you're summoning

  2. Anonymous

    Remember: a regex you can still understand after lunch clearly isn’t using enough backreferences - time to deploy the cat again

  3. Anonymous

    After 20 years of writing regex, I've finally accepted that the cat method produces cleaner patterns than my attempts to remember the difference between positive lookaheads and atomic groups

  4. Anonymous

    This perfectly captures why every team has that one senior engineer who wrote a regex three years ago that nobody dares touch - not because it's critical infrastructure, but because understanding it would require archaeological excavation of Stack Overflow posts from 2009. The real tragedy? That cat-generated pattern probably still has fewer edge cases than the 'properly documented' regex you inherited from the previous architect

  5. Anonymous

    Regex is the only DSL where keyboard mashing can pass code review - until RE2 saves prod from your cat’s O(2^n) backtracking art

  6. Anonymous

    Regex enlightenment: when cat paws yield patterns that outpace your hand-optimized backtracking hell

  7. Anonymous

    Regex: the only DSL where my cat can ship an exponential‑time backtracking bomb that still gets LGTM because nobody wants to own it

Use J and K for navigation