Re: Globbing versus regular expressions

Liste des GroupesRevenir à cu shell 
Sujet : Re: Globbing versus regular expressions
De : 643-408-1753 (at) *nospam* kylheku.com (Kaz Kylheku)
Groupes : comp.unix.shell
Date : 21. Jul 2024, 16:09:46
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <20240721080121.915@kylheku.com>
References : 1
User-Agent : slrn/pre1.0.4-9 (Linux)
On 2024-07-21, Axel Reichert <mail@axel-reichert.de> wrote:
Hi all,
>
a colleague (new to command line wizardry) seemed puzzled by the
existence of both globbing for file names (shell) and regular
expressions for strings (many other command line tools).

path name globs are regular expressions. You can mechanically translate
globs to regular expressions.

If you have a regex engine and access to traversing the filesystem,
you can write glob.

globs are a syntactic sugar for a subset of regex. They are not as
powerful, but they are more concise and ergonomic for their target
use cases.

Since regexes are (at quick glance) a superset of globs, why not
consistently use the former for both file names and strings? The

globs are used for strings; check out the case statement in the
POSIX shell language, and the fnmatch C library function.

You see uses of glob-like processing outside of Unix.
For instance, the Redirector browser extension for Firefox
uses glob-like patterns such as:

  https://example.com/*/foo/*.html

where in the right hand side of the rewrite pattern you can refer
to the parts matched by the * syntax, in left to right order
using $1, $2, ...

few additional keystrokes (.* instead of *) are IMHO easily compensated
for by the more powerful capabilities of regexes.

So you might think, but it would actually be a nuisance, and
trip up people. (Even the coders, never mind non-coders.)

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca

Date Sujet#  Auteur
21 Jul 24 * Globbing versus regular expressions10Axel Reichert
21 Jul 24 +- Re: Globbing versus regular expressions1Janis Papanagnou
21 Jul 24 +- Re: Globbing versus regular expressions1Joerg Mertens
21 Jul 24 +- Re: Globbing versus regular expressions1Kaz Kylheku
21 Jul 24 +- Re: Globbing versus regular expressions1Lawrence D'Oliveiro
2 Aug 24 +* Re: Globbing versus regular expressions2Ed Morton
5 Aug 24 i`- Re: Globbing versus regular expressions1Keith Thompson
2 Aug 24 `* Re: Globbing versus regular expressions3Ed Morton
10 Aug 24  `* Re: Globbing versus regular expressions2Axel Reichert
10 Aug 24   `- Re: Globbing versus regular expressions1Lawrence D'Oliveiro

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal