help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] ${var//!([[:class:]])} removing characters of the [:clas


From: Mart Frauenlob
Subject: Re: [Help-bash] ${var//!([[:class:]])} removing characters of the [:class:]
Date: Sun, 27 Jan 2013 11:11:59 +0100
User-agent: Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/20130107 Thunderbird/17.0.2

On 27.01.2013 10:45, Pierre Gaston wrote:
On Sun, Jan 27, 2013 at 11:34 AM, Mart Frauenlob
<address@hidden> wrote:
On 27.01.2013 10:08, Pierre Gaston wrote:

On Sun, Jan 27, 2013 at 10:46 AM, Mart Frauenlob
<address@hidden> wrote:

On 27.01.2013 09:31, Pierre Gaston wrote:

[...]

because inside [[:alpha:]] only matches 1 character
so abc is not match by alpha since it is 3 character, abc is the
longest string that doesn't match and it removed
you get abc with:
    x=abc;echo ${x/!(+([[:alpha:]]))}


thank you very much for that explanation!

have a nice day


cool, just for completion (well ok there may be even more)about the
not so obvious things with !()...you should take care that the empty
string is also a "non-match":

$ x=abc;echo ${x//!(+([[:alpha:]]))/r}
rarbrc

each empty string before and after the chars is not matched by "one or
more alpha" and is replaced


My previous error is obvious to me now, but this one I'm not sure if I
understand.
Does this mean a string in bash has internally separated each character with
a NULL char?

No, it's just that by definition the negation of "one or more thing A"
can be "thing B" but it can also be "nothing" and there is "nothing"
between each character but "nothing" is not a physical byte

in the regex world, the example of this is:
$ echo foo | sed 's/m*/a/g'
afaoaoa
Here 0 or more m matches the "nothing" between the characters

The common mistake is to think "ls *!(.jpg)" will list all the files
but the .jpg
It doesn't work, because * can match "foo.jpg" and !(.jpg) can match
the empty string after it. (ls !(*.jpg) is what should be used)


ok, this nothing really is something :)
thanks



reply via email to

[Prev in Thread] Current Thread [Next in Thread]