Sujet : Re: Useless Use Of Regexes
De : Pancho.Jones (at) *nospam* protonmail.com (Pancho)
Groupes : comp.os.linux.miscDate : 24. Mar 2025, 22:48:26
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vrsjva$1oouq$1@dont-email.me>
References : 1
User-Agent : Mozilla Thunderbird
On 3/24/25 20:34, Lawrence D'Oliveiro wrote:
Besides the traditional “Useless Use Of Cat” (UUOC) newbie faux pas,
we can add “Useless Use Of Regexes”.
These can often be quite subtle. I spotted one obvious instance here
<https://www.zdnet.com/article/5-ways-i-use-regex-in-linux-and-why-theyre-so-essential/>,
namely this one:
ip addr | grep -Eo '192\.168\.1\.[0-9]{1,3}'
Tut Tut!
$ip addr | grep -E '192\.168\.0\.([0-1]?[0-9]?[0-9]?|2[0-4][0-9]|25[0-5])'
Solve a problem with a RegEx, now you have two problems :-)
which can be more easily written using features built into iproute2 itself:
ip addr show to 192.168.1.0/24
Seriously, though, it is often easier to filter output from a standard command with grep, than it is to learn all the command flags.