Sujet : Re: Globbing versus regular expressions
De : 643-408-1753 (at) *nospam* kylheku.com (Kaz Kylheku)
Groupes : comp.unix.shellDate : 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/txrCygnal: Cygwin Native Application Library: http://kylheku.com/cygnalMastodon: @Kazinator@mstdn.ca