Hacker News new | past | comments | ask | show | jobs | submit login

I think at this point something as expressive as PCRE should be table stakes for any language aspiring to be used for text processing. It's so successful that GNU grep added support:

-P, --perl-regexp Interpret I<PATTERNS> as Perl-compatible regular expressions (PCREs). This option is experimental when combined with the -z (--null-data) option, and grep -P may warn of unimplemented features.




PCRE patterns are inherently unmaintainable; they're not (naturally) compositional or testable. They also cause unpleasant surprises due to accidental Turing completeness (indeed that's one of the more common causes of production outages that I've seen). IMO it's past time for newer languages to offer better alternatives, e.g. really good parser combinator support in the standard library.


Yes and no ... I love Haskell's Parsec derived family of libraries (especially Attoparsec for fast and Megaparsec for detailed parsing).

But sometimes you just need to throw something together fast. Eg search and replace in Vim uses regexps.


Perl 6 Grammars maybe?



Rather structural matchers.

Like match in functional langs or lisp matchers https://www.cliki.net/pattern%20matching Unification is so much better than regex hacks.


Raku/Perl6 grammars are quite nice (particularly if the have improved support for raw strings).


Still, when you have a well-defined input and you can treat data as a flat string (no hierarchy), PCRE is probably the best choice you have - and certainly the fastest one.


True regular expressions (that get compiled to DFAs) are faster if you don't need the funky PCRE features, and you usually don't.


Is there any popular language out there that implements DFA or Thompson NFA regexps (beside awk)?


`ripgrep` also supports the `-P` option (but PCRE2 instead of PCRE, so as to support replacements as well)


I wonder if there’s a site that compares the speed and capability of regex in different languages?


Not exactly what you asked for, but one aspect: https://swtch.com/~rsc/regexp/regexp1.html

(Scroll down to this plot: https://swtch.com/~rsc/regexp/grep1p.png




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

Search: