4 ms·
10 years and a dozen problems? Conversely, I encounter pattern matching problems and use RegEx near daily. Both these perspectives are anecdata, neither are use
by RadiozRadioz 4y ago
10 years and a dozen problems? Conversely, I encounter pattern matching problems and use RegEx near daily. Both these perspectives are anecdata, neither are useful.
> and probably a lot more performant to boot
I highly doubt your home-grown pattern matching functions could beat the decades of optimization that have gone into RegEx engines, in anything but the most trivial of patterns (like the one demonstrated here). Creating your own ad-hoc pattern matcher instead of using the ubiquitous one built into your language is like the junior in the article re-implementing JOINs. Sure, you may be able to beat the engine occasionally on particularly simple patterns, but I guarantee you'll lose out overall.
RegEx is not inherently slow, and it is definitely possible to maintain. See industries with serious text processing demands like bioinformatics, where Perl is still used extensively. They could not operate like they do if they shied away from RegEx like many developers seem to.
- pixelbath 4y ago> Creating your own ad-hoc pattern matcher instead of using the ubiquitous one built into your language GP was using LINQ, which is a first-class language construct in C#. I'll grant that it may not be _as_ optimized as Perl's regex routines, but it's hardly ad-hoc or slow.
- RadiozRadioz 4y agoYes, the linked example falls in the category of "particularly simple patterns" I mentioned. This strategy only works for such simple patterns; add in a single alternation with a common base and the naïve iteration strategy falls apart. Implementing a sensible algorithm to evaluate such a pattern would require much more code than a couple of brackets, would not benefit from RegEx caching, etc.
- Merad 4y ago> I highly doubt your home-grown pattern matching functions could beat the decades of optimization that have gone into RegEx engines On the contrary, the All() method used here (which is part of the .Net standard library) is literally just a loop that evaluates each item in the collection to verify that they all match the predicate function. It'll be able to check hundreds if not thousands of characters in the time that it takes the regex engine to initialize and parse the pattern.
- ttfkam 4y agoIt other words, you're not caching/reusing you regex patterns? I think I see the cause of one of your recurring performance problems.
- RadiozRadioz 4y agoInteresting how you conveniently ignored the second half of my sentence. I will paste it here: > in anything but the most trivial of patterns (like the one demonstrated here)