4 ms·
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 G
by nieve 5y ago
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.
- brightball 5y agoI wonder if there’s a site that compares the speed and capability of regex in different languages?
- kqr 5y agoNot exactly what you asked for, but one aspect: https://swtch.com/~rsc/regexp/regexp1.html https://swtch.com/~rsc/regexp/regexp1.html (Scroll down to this plot: https://swtch.com/~rsc/regexp/grep1p.png https://swtch.com/~rsc/regexp/grep1p.png
- asicsp 5y ago`ripgrep` also supports the `-P` option (but PCRE2 instead of PCRE, so as to support replacements as well)
- lmm 5y agoPCRE 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.
- fho 5y agoYes 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.
- cutler 5y agoPerl 6 Grammars maybe?
- yesbut 5y agoLink for anyone interested: https://docs.raku.org/language/grammar_tutorial https://docs.raku.org/language/grammar_tutorial
- rurban 5y agoRather structural matchers. Like match in functional langs or lisp matchers https://www.cliki.net/pattern%20matching https://www.cliki.net/pattern%20matching Unification is so much better than regex hacks.
- ggrrhh_ta 5y agoRaku/Perl6 grammars are quite nice (particularly if the have improved support for raw strings).
- deleted 5y ago[deleted]
- ivanhoe 5y agoStill, 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.