-- Leo's gemini proxy

-- Connecting to thrig.me:1965...

-- Connected

-- Sending request

-- Meta line: 20 text/gemini

Regular Expression Alternation


    my $command = qr/(ab)/;

Business needs might prompt the addition of longer command names, so instead of just ab one might add:


    my $command = qr/(ab|abbr|abbreviate)/;

This is buggy; the regular expression will never match abbr nor abbreviate.


    $ aslines ab abbr abbreviate | perl -nE 'say $1 if /(ab|abbr|abbreviate)/'
    ab
    ab
    ab

Causes of this bug are where the alternation is thrown together at random--and never tested nor reviewed, an all too common case--or where software automatically builds the alternation and that building software is buggy. The Data::Munge Perl module by contrast takes a number pains in the list2re function to get this right.


https://metacpan.org/pod/Data::Munge


Other software or people writing software may be less enlightened about such matters. Buyer beware?


tags #regex #perl

-- Response ended

-- Page fetched on Tue May 21 22:52:58 2024