From: Janis Papanagnou on
mallin.shetland wrote:
> On Saturday 23 January 2010 11:59 Janis Papanagnou wrote:
>
>> Of course it does. File globbing uses regular expressions.
>
> You are quite confused.

Not the least. (Browse the archives.)

> Regular expression is a thing, globbing
> is a totally different (and simpler) thing.

Simpler probably for WinDOS users who had historically just
the * and ? regular expression metacharacters supported in their
command interpreters. In Kornshell, just to name one example, you
have the @(...|...), *(...|...), +(...|...), and even the
powerful !(...|...) regular expression meta-constructs, in addition
to the more primitive * ? [...] [^...] regexps that can be used in
file globbing (i.e. regexps coupled to file object search), as well.

Globbing is the use of a regular expression to select the subset
of matching files; i.e. regular expressions coupled to a concrete
set ob objects on the file system. In shell you can disable file
globbing and stay with the regular expressions alone, for example
in case statements or some implementation's if [[...]] constructs.

> Regular expressions belong to the theory of formal languages

Yes. Or more precise; regular expressions are the set of formal
languages that are collected under the Chomsky-3 grammar hierarchy
and can be processed by finite automata. There's not one language
and grammar, there are a lot who are collected unter that hierarchy.
But the "power" of all the Chomsky-3 languages is the same; they
are the regular expressions languages. The difference is the way
how they can be used, a convenience issue.

> while globbing is the use of whildcard and subset.

You've got confused. The point is that the so called "wildcards"
are just regular expression metacharacters that are used in both,
in regular expressions supported by the regexp library as well as
in regular expressions supported by "file globbing".

Different libraries and tools support regular expressions differently;
while in one Chomsky-3 regular expression language you write +([0-9])
in another one you write [0-9]+ or \d+ or [0-9][0-9]* or whatever,
depending how well it's supported for the users convenience.

One additional confusion arises from time to time; the misconception
that regular expressions would be just (and exactly) what is supported
by the regexp library or the extended form thereof; this is also false.

Janis

>>[...]
From: Jon LaBadie on
mallin.shetland wrote:
> Addì sabato 23 gennaio 2010 10:41 Tuxedo scrisse:
>
>> I'd like to remove from within a shell script a series of files with the
>> following number format:
>> 004023.jpg
>> 004024.jpg
>> 004025.jpg
>> etc.
>> ...
>
> This issue does not concerne regular expression at all!
> This task can be done using brace epansion; I.E. in bash and ksh
> you type:
>
> rm -f 004{0..9}{0..9}{0..9}.jpg
>
> In ksh you can type also:
>
> rm -f 004{0..999%03d}.jpg
>

A major distinction between the pattern matching suggestion (btw it is
not regular expression) and your brace expansion is that pattern
matching generates 'rm' arguments only for files that exist whereas
brace expansion generate all 1000 arguments regardless of the
existence of a matching filename.

Be prepared to discard many "file does not exist" error messages.

From: Seebs on
On 2010-01-23, Janis Papanagnou <janis_papanagnou(a)hotmail.com> wrote:
> Of course it does. File globbing uses regular expressions.

No, it doesn't.

File globbing uses shell patterns. They're confusingly similar in
a few ways, but quite different.

-s
--
Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam(a)seebs.net
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
From: Stephane CHAZELAS on
2010-01-23, 11:43(+01), mallin.shetland:
> Add� sabato 23 gennaio 2010 10:41 Tuxedo scrisse:
>
>> I'd like to remove from within a shell script a series of files with the
>> following number format:
>> 004023.jpg
>> 004024.jpg
>> 004025.jpg
>> etc.
>> ...
>
> This issue does not concerne regular expression at all!
> This task can be done using brace epansion; I.E. in bash and ksh
> you type:
>
> rm -f 004{0..9}{0..9}{0..9}.jpg

FYI, that syntax was originally introduced (amongst shells) in
zsh (which is obviously inspired from elsewhere probably perl)
and then copied by ksh93 and bash (though with variations).

> In ksh you can type also:
>
> rm -f 004{0..999%03d}.jpg
[...]

And in zsh

rm -f 004{000..999}.jpg

Or you can use zsh's extended globbing:

rm <4000-4999>.jpg

(you need "setopt extendedglob", those globbing operators are
not on by default as they introduce potential conflict with the
redirection operators)

--
St�phane
From: Janis Papanagnou on
Seebs wrote:
> On 2010-01-23, Janis Papanagnou <janis_papanagnou(a)hotmail.com> wrote:
>> Of course it does. File globbing uses regular expressions.
>
> No, it doesn't. File globbing uses shell patterns.

Yes, and "patterns are often described using regular expressions" [Wikipedia]

> They're confusingly similar in a few ways, but quite different.

In which way different? (Beyond differences in usability that I mentioned
upthread.) It would be helpful to elaborate that beyond a simple statement.
Can you provide a standard grep(1) example that we cannot implement with
pattern matching capabilities (globbing without files) of a typical shell?
Curious.

Janis

>
> -s