Hacker News new | ask | show | jobs
by Timwi 342 days ago
What would you propose as an alternative to regexes that provides the same functionality without the unreadable syntax?

I wrote something like that in C# once [0] but I'm not getting the impression that there's a lot of demand for that kind of thing.

[0] https://github.com/Timwi/Generex

3 comments

Chiming in - I've found the Pattern type in Unison[0] to be very nice to use. When you're just using the built-in patterns, it is similar to verbose regex. The real power of them is that it's easy to define, name, and re-use sub-patterns. I think it's similar to parser combinators in this way, like nom from rust[1].

[0] https://share.unison-lang.org/@unison/website/code/main/late...

[1] https://docs.rs/nom/latest/nom/

There's a whole list of alternative syntaxes here:

https://github.com/oils-for-unix/oils/wiki/Alternative-Regex...

I haven't actually used them because generally the right alternative to a regex is a proper parser.

Parsing expression grammars (pegs) are usually IME more maintainable long term, partially just because of much more testable and composable they are
I suspect but am not sure that PEGs cannot do negative nor positive lookbehind, but it is not a very used feature.
Yeah that’s true IIRC but it’s rarely been a problem for my usage!