Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Tedious and annoying for one-off commands maybe. It's like regex. Pretty compelling if you're writing a one-off pattern, you get immediate feedback and then you throw it away.

But it's not a good idea to use regexes in code that you're going to use long term. It's justifiable for simple regexes, and many people go against this advice, but really for anything remotely complex regexes become totally unreadable and extremely bug prone. Complex regexes are a huge code smell and array languages are pretty much one enormous regex.



Yeah never had that issue; maybe it's because I have been doing regexes (and apl which people call write only as well) for 30 years: it is not unreadable, nor throw away. I find it far more readable than the alternatives; reading pages of elaborate 'pseudocode' is more bothersome/time consuming than a oneliner to me.


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


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!




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: