From: Kaz Kylheku on
On 2010-01-24, Janis Papanagnou <janis_papanagnou(a)hotmail.com> wrote:
> (Must have a look to understand what's meant with differences between REs.)

Regexes denote sets of strings: (a|b) denotes { "a" "b" }.

The commonly understood difference between two regexes R1-R2 is set
difference: the set of strings matched by R1, excluding those matched by
R2.

If you have complement (~) and intersection (&), you can express
it as R1&~R2: I.e. the intersection of R1 and the complement of R2.
From: Janis Papanagnou on
Kaz Kylheku wrote:
> On 2010-01-24, Janis Papanagnou <janis_papanagnou(a)hotmail.com> wrote:
>> (Must have a look to understand what's meant with differences between REs.)
>
> Regexes denote sets of strings: (a|b) denotes { "a" "b" }.
>
> The commonly understood difference between two regexes R1-R2 is set
> difference: the set of strings matched by R1, excluding those matched by
> R2.
>
> If you have complement (~) and intersection (&), you can express
> it as R1&~R2: I.e. the intersection of R1 and the complement of R2.

Thanks for replying. These concepts were clear, though.

What rather puzzled me was the meaning of a difference when I was asking
about an regexp representation that is equivalent to the globbing form;
I specifically don't want to see any difference here. That was why I want
to look up that discussion.

Janis
From: Stephane CHAZELAS on
2010-01-24, 22:51(+00), pk:
> Janis Papanagnou wrote:
>
>> Still interested in an regexp expression conforming to !(...) ext. glob.
>
> Well if lookaround assertions are available, it's trivially done with
> something like
>
> (?!whatyoudontwant).*.ext
>
> or equivalent.
>
> (Yes, we're way out of the "regular" regexp domain here, probably even more
> than with backreferences)
>
> However, I don't think any shell implements that.

zsh has support for PCREs. AT&T ksh, bash and ksh support !(...)
zsh has the ~ operator which can be used as a look-ahead:

*.ext~whatyoudontwant*

--
St�phane
From: Icarus Sparry on
On Mon, 25 Jan 2010 10:20:14 +0100, Janis Papanagnou wrote:

> Kaz Kylheku wrote:
>> On 2010-01-24, Janis Papanagnou <janis_papanagnou(a)hotmail.com> wrote:
>>> (Must have a look to understand what's meant with differences between
>>> REs.)
>>
>> Regexes denote sets of strings: (a|b) denotes { "a" "b" }.
>>
>> The commonly understood difference between two regexes R1-R2 is set
>> difference: the set of strings matched by R1, excluding those matched
>> by R2.
>>
>> If you have complement (~) and intersection (&), you can express it as
>> R1&~R2: I.e. the intersection of R1 and the complement of R2.
>
> Thanks for replying. These concepts were clear, though.
>
> What rather puzzled me was the meaning of a difference when I was asking
> about an regexp representation that is equivalent to the globbing form;
> I specifically don't want to see any difference here. That was why I
> want to look up that discussion.
>
> Janis

I am sure we agree that going from a common glob form (whatever that
means exactly) to a common regular expression (whatever that also means
exactly) is pretty simple. Add anchors, change . to \., change ? to .,
change * to .*, maybe muck around with the negation character in
character classes.

So the question is how to turn a negated glob, e.g. "!(hello)" into a
regular expression. Now this means "anything, except for something that
matches "hello". A RE that matches "hello" is "^hello$", and an RE that
matches anything is "^.*$", and you want something that matches the
latter but not the former, or the "difference" between the two.

The discussion in comp.compilers reminded people that this could be
expressed as an RE. I gave one that was almost correct (I think I just
left out matching the empty string) and Kaz gave another for the simple
case of "!(hello)".