I don't know if ABNF expressions are as "powerful" as regexes, but for all the uses I've ever had for regexes, ABNF would make that work easier, more readable, more maintainable, and commentable

Honestly thinking of shifting to ABNF for the projects where I end up using regexes a lot, would be nice to be able to come back to code a year later and actually understand how my pattern-matching works

@gaeel When 10% of the internet went down a week ago due to a RegEx error (, it did make me wonder if there are better alternatives. I wish more programming languages had built-in support for ABNF.

@gendor Note that ABNF doesn't prevent catastrophic backtracking (see picture which includes an expression that can cause issues on both RegEx and ABNF), and that kind of error is just as counter-intuitive in both forms

Maybe using ABNF would have prevented this mistake, but either way, ABNF is just so much more legible

@gendor Although I'm thinking now, and maybe I'm just confused, but...
If I remember from comp.sci, regex and FSM are equivalent, and all non-deterministic FSM can be made deterministic
The reason catastrophic backtracking happens is because the equivalent FSM isn't deterministic, so why don't regex systems do this?

I'll look into this later, I'm probably not seeing something important, because it seems too obvious a fix to such a huge problem

@gendor Okay, turns out what we call regexes in programming aren't actually regexes. If they were we could write safe, linear-time implementations, but we wouldn't be able to have backreferences and other nice tools for extracting data from matched patterns

@gaeel Yeah, I think legibility is what makes it so much better. Both in terms of making it easier to write, but also to make it easier to understand when it comes to code review.

@gendor @gaeel yeah I very much like the legibility. I once had a senior programmer take me to task for my regexes being inefficient or non-compact or somesuch and I was like, "but if I break this into several small regexes that run sequentially, people in the future will be able to read this code and understand what it does. I'd rather have understandable code than marginally faster code."

He didn't reply

Sign in to participate in the conversation

Revel in the marvels of the universe. We are a collective of forward-thinking individuals who strive to better ourselves and our surroundings through constant creation. We express ourselves through music, art, games, and writing. We also put great value in play. A warm welcome to any like-minded people who feel these ideals resonate with them. Check out our Patreon to see our donations.