logoalt Hacker News

seizethecheese • last Friday at 6:48 PM • 4 replies • view on HN

My coworker used to teach non-technical people how to code. Students always found regex hard to understand.

Let's be honest, regex can be hard to understand even for technical people. (At least it's hard for me.)

So coworker built this to help anyone understand arbitrary regex commands.

AI disclosure: this was built using Agent Duel, a local coding agent arena system (https://github.com/bottomless/agent-duel). Promotion disclosure: our company is building agent duel. To test it and find bugs we are building passion projects through the system. I nonetheless thought HN would find this interesting.


Replies

crazygringo • today at 2:00 PM

Regex is conceptually incredibly easy to understand.

But regex is also syntactically designed by Satan himself.

Most programming languages use commands that are semantically understandable, like "for" and "let" and "return" and mostly symbols we already know like "+" and "=". They use newlines and indentation for organization. And they put multiple commands on multiple lines and you can add comments and everything.

Regex is exclusively punctuation, with its own idiosyncratic meanings, all compressed into a single line, zero organization, zero comments, and impossible to remember what each symbol does if you don't use it daily. Not to mention the nightmare of escaping regexes when expressed as strings, on top of escaping regex symbols within the regex itself.

I swear it's high time we come up with a regex replacement that looks like normal Python code or HTML or something. So instead of:

  ^(\+\d{1,3}-?)?\d{3}-\d{3}-\d{4}$
We would write something like:

  <start>
    <optional>  # Optional country code
      "+"
      <digit>[1-3]
      "-"
    </optional>
    <digit>[3]  # Area code
    "-"
    <digit>[3]
    "-"
    <digit>[4]
  <end>
Same thing. But one is completely inscrutable to someone who hasn't learned regex, while with the other you can guess pretty easily how it works...
➕ show 11 replies
Syzygies • today at 7:49 PM

America's Cup and Formula One races are won at the design stages. We praise the drivers, but what succeeds is the engineering.

If billions of dollars of IPO value were at stake, competing to use animation to convey an understanding to test subjects, this design would be toast. The model is cripplingly realistic, wasting most of its cognitive bandwidth on provoking a "Gee willikers, it really looks like someone built that out of wood!" reaction, leaving us to squint to see the balls or the parts of the machine implementing the logic. There's a particular genius to logo design, that needs to be applied here. If this were instead a cartoon animation, Walt Disney dosed the coffee one day at the studio to see what his animators could do, we'd get a visualization that better used its cognitive bandwidth to establish an icon language with the viewer.

The abacus is the T-shirt for this idea. Like a musical instrument, one can imagine operating an abacus without holding one, and some shopkeepers were able to leave theirs in a drawer after enough practice. Beads, like balls, leverage our brains' ability to manipulate physical reality, but the idea of counting became more vivid as the abacus design grew more streamlined. It not only became easier to build and operate, but it became a more effective "thought worm" implant into our minds.

We make contact with aliens, and in their museums they have an abacus for regular expressions. What does it look like?

This is important to get right, because soon AI will communicate with us using Pixar-quality 3D animation, generated in real time for each conversational turn. Many people still think of AI communication as exchanging "text message" prompts, but for my math research I'm already getting illustrated PDF slide decks as AI's responses to me in single conversational turns. One just has to ask; the form AI communication takes is only limited by our imagination.

Feynman diagrams and the like as rare exceptions, scientific communication is still mired in "telegraph" form, math symbols one reads along lines of text that once lived on physical paper. As future generations adapt to visual symbolic reasoning, the animations AI will use to communicate with us will evolve from representational to abstract art, for a "fatter pipe" pouring symbolic information into our minds. They'll find the "thought worms" that best hack our minds, make us smarter.

I'd love to see what your regex viewer would look like, if you were imagining this future.

atoav • today at 11:04 AM

I am mostly an autodidact and learned bits regex on the fly when I needed it and I was always baffled why people have auch a hard time with it.

The problem IMO is that a lot of the traditional teaching material starts with the complexity (and impressive possibilities) of regex, when the best way to start learning it is probably just thinking about it as an extension to simple text matching.

Getting to know regex fully is in fact complicated, getting know enough regex to filter/search/replace 90% of everything you will always need is not too complicated.

➕ show 1 reply
ogogmad • today at 11:02 AM

Really cool. Do you teach people the mechanics, like what the app shows? Because I wonder if that actually makes it harder. I'm wondering about where the hard bits are, given that it all boils down to just:

  "|", which means "or"
  ".", which means "any symbol"
  "?", which means "at most once",
  "*", which means "however many times"
  "+", which means "at least once"
Maybe encountering it next to PEG scrambles your brain.
➕ show 1 reply