Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Matching ']' in glob patterns
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  13 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
bmburst...@gmail.com  
View profile  
 More options Jun 3 2012, 12:18 pm
Newsgroups: comp.lang.tcl
From: bmburst...@gmail.com
Date: Sun, 3 Jun 2012 09:18:36 -0700 (PDT)
Local: Sun, Jun 3 2012 12:18 pm
Subject: Matching ']' in glob patterns
Can anyone answer my question that I posted here: http://stackoverflow.com/questions/10871855/tcl-match-closing-bracket...

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
George Petasis  
View profile  
 More options Jun 3 2012, 1:01 pm
Newsgroups: comp.lang.tcl
From: George Petasis <petas...@yahoo.gr>
Date: Sun, 03 Jun 2012 20:01:36 +0300
Local: Sun, Jun 3 2012 1:01 pm
Subject: Re: Matching ']' in glob patterns
Στις 3/6/2012 19:18, ο/η bmburst...@gmail.com έγραψε:

> Can anyone answer my question that I posted here: http://stackoverflow.com/questions/10871855/tcl-match-closing-bracket...

You can use braces:

set x {]}

switch -glob $x {
   {]} {puts "MATCH \]"}

}

George

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Eugene  
View profile  
 More options Jun 3 2012, 1:14 pm
Newsgroups: comp.lang.tcl
From: Eugene <eugene.mind...@gmail.com>
Date: Sun, 03 Jun 2012 21:14:48 +0400
Local: Sun, Jun 3 2012 1:14 pm
Subject: Re: Matching ']' in glob patterns
On 03.06.2012 21:01, George Petasis wrote:
> Στις 3/6/2012 19:18, ο/η bmburst...@gmail.com έγραψε:
>> Can anyone answer my question that I posted here:
>> http://stackoverflow.com/questions/10871855/tcl-match-closing-bracket...

> You can use braces:

> set x {]}

> switch -glob $x {
> {]} {puts "MATCH \]"}
> }

> George

or just shield a bracket with a backslash: set x \]

--
Best regards, Eugene.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Uwe Klein  
View profile  
 More options Jun 3 2012, 1:04 pm
Newsgroups: comp.lang.tcl
From: Uwe Klein <u...@klein-habertwedt.de>
Date: Sun, 03 Jun 2012 19:04:01 +0200
Local: Sun, Jun 3 2012 1:04 pm
Subject: Re: Matching ']' in glob patterns

bmburst...@gmail.com wrote:
> Can anyone answer my question that I posted here: http://stackoverflow.com/questions/10871855/tcl-match-closing-bracket...

set pattern abc\]def
set glob *\\\]*

puts stderr glob:$glob\ pattern:$pattern

switch -glob $pattern \
           $glob {
                 puts stderr  glob:$pattern
         } default {
                 puts stderr nomatch
         }

uwe


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
bmburst...@gmail.com  
View profile  
 More options Jun 3 2012, 2:23 pm
Newsgroups: comp.lang.tcl
From: bmburst...@gmail.com
Date: Sun, 3 Jun 2012 11:23:08 -0700 (PDT)
Local: Sun, Jun 3 2012 2:23 pm
Subject: Re: Matching ']' in glob patterns

All these options are not the same as the question. I need to match the right bracket as part of a character set. I need to match all types of brackets, and so am using the glob "[()[]{}]", which of course doesn't work.

Does Tcl have fall-through handling of cases? As a workaround I could match the string with the character class containing all the other types, and then match this one specific case separately and fall through.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
George Petasis  
View profile  
 More options Jun 3 2012, 3:01 pm
Newsgroups: comp.lang.tcl
From: George Petasis <petas...@yahoo.gr>
Date: Sun, 03 Jun 2012 22:01:42 +0300
Local: Sun, Jun 3 2012 3:01 pm
Subject: Re: Matching ']' in glob patterns
Στις 3/6/2012 21:23, ο/η bmburst...@gmail.com έγραψε:

Your question was not clear. Have you looked at the manual of switch?

switch -regexp $x {
  {[\(\)\[\]\{\}]} {puts match}

}

George

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
bmburst...@gmail.com  
View profile  
 More options Jun 3 2012, 3:11 pm
Newsgroups: comp.lang.tcl
From: bmburst...@gmail.com
Date: Sun, 3 Jun 2012 12:11:13 -0700 (PDT)
Local: Sun, Jun 3 2012 3:11 pm
Subject: Re: Matching ']' in glob patterns

Thank you. I don't know why I didn't think of using regex instead of glob. But this seems to be a bug in Tcl that the ']' can't be escaped in a glob pattern character set.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Alexandre Ferrieux  
View profile  
 More options Jun 3 2012, 3:12 pm
Newsgroups: comp.lang.tcl
From: Alexandre Ferrieux <alexandre.ferri...@gmail.com>
Date: Sun, 3 Jun 2012 12:12:51 -0700 (PDT)
Local: Sun, Jun 3 2012 3:12 pm
Subject: Re: Matching ']' in glob patterns
On Jun 3, 8:23 pm, bmburst...@gmail.com wrote:

> I need to match the right bracket as part of a character set. I need to match all types of brackets, and so am using the glob "[()[]{}]", which of course doesn't work.

To my knowledge, this is not possible directly with glob matching.
However, it is easy with regexp matching: just put the "]" as first in
range:

   regexp {[][(){}]} $x

See the "BRACKET EXPRESSIONS" section in the re_syntax manpage.

-Alex


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
George Petasis  
View profile  
 More options Jun 3 2012, 4:10 pm
Newsgroups: comp.lang.tcl
From: George Petasis <petas...@yahoo.gr>
Date: Sun, 03 Jun 2012 23:10:40 +0300
Local: Sun, Jun 3 2012 4:10 pm
Subject: Re: Matching ']' in glob patterns
Στις 3/6/2012 22:11, ο/η bmburst...@gmail.com έγραψε:

> Thank you. I don't know why I didn't think of using regex instead of glob. But this seems to be a bug in Tcl that the ']' can't be escaped in a glob pattern character set.

I am not sure I understand. Why can't ] be escaped?
\] is a normal character, and can be used in any glob pattern.

George


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Alexandre Ferrieux  
View profile  
 More options Jun 3 2012, 5:09 pm
Newsgroups: comp.lang.tcl
From: Alexandre Ferrieux <alexandre.ferri...@gmail.com>
Date: Sun, 3 Jun 2012 14:09:26 -0700 (PDT)
Local: Sun, Jun 3 2012 5:09 pm
Subject: Re: Matching ']' in glob patterns
On Jun 3, 10:10 pm, George Petasis <petas...@yahoo.gr> wrote:

> Στις 3/6/2012 22:11, ο/η bmburst...@gmail.com έγραψε:

> > Thank you. I don't know why I didn't think of using regex instead of glob. But this seems to be a bug in Tcl that the ']' can't be escaped in a glob pattern character set.

> I am not sure I understand. Why can't ] be escaped?
> \] is a normal character, and can be used in any glob pattern.

Apparently not:

 % string match {[\]a]} a
 0

-Alex


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Andreas Leitgeb  
View profile  
 More options Jun 4 2012, 6:37 am
Newsgroups: comp.lang.tcl
From: Andreas Leitgeb <a...@gamma.logic.tuwien.ac.at>
Date: Mon, 4 Jun 2012 10:37:18 +0000 (UTC)
Local: Mon, Jun 4 2012 6:37 am
Subject: Re: Matching ']' in glob patterns

Alexandre Ferrieux <alexandre.ferri...@gmail.com> wrote:
> On Jun 3, 8:23 pm, bmburst...@gmail.com wrote:
>> I need to match the right bracket as part of a character set.
>> I need to match all types of brackets, and so am using the
>> glob "[()[]{}]", which of course doesn't work.
> To my knowledge, this is not possible directly with glob matching.

FWIW, in unix-shell (bash - probably others, too):
$ touch 'abc[def]ghi'
$ echo *[]]*
abc[def]ghi

Was it an oversight in the specification of Tcl's glob, or was it
deliberately left out?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Alexandre Ferrieux  
View profile  
 More options Jun 4 2012, 8:13 am
Newsgroups: comp.lang.tcl
From: Alexandre Ferrieux <alexandre.ferri...@gmail.com>
Date: Mon, 4 Jun 2012 05:13:07 -0700 (PDT)
Local: Mon, Jun 4 2012 8:13 am
Subject: Re: Matching ']' in glob patterns
On Jun 4, 12:37 pm, Andreas Leitgeb <a...@gamma.logic.tuwien.ac.at>
wrote:

> Alexandre Ferrieux <alexandre.ferri...@gmail.com> wrote:
> > On Jun 3, 8:23 pm, bmburst...@gmail.com wrote:
> >> I need to match the right bracket as part of a character set.
> >> I need to match all types of brackets, and so am using the
> >> glob "[()[]{}]", which of course doesn't work.
> > To my knowledge, this is not possible directly with glob matching.

> FWIW, in unix-shell (bash - probably others, too):
> $ touch 'abc[def]ghi'
> $ echo *[]]*
> abc[def]ghi

> Was it an oversight in the specification of Tcl's glob, or was it
> deliberately left out?

From a 'fossil annotate' on tclUtil.c, function Tcl_StringCaseMatch:

16f0a0d493 1999-12-04     hobbs:            }
16f0a0d493 1999-12-04     hobbs:            while (1) {
16f0a0d493 1999-12-04     hobbs:                if ((*pattern == ']') || (*pattern
== '\0')) {
16f0a0d493 1999-12-04     hobbs:                    return 0;
16f0a0d493 1999-12-04     hobbs:                }

(and the lack of special casing nor comments to that regard)
... it seems that this Day One limitation comes from the fact that
nobody cared (nor cares, to be frank) about strict compatibility with
shell globbing. In hindsight, 99% compat is okay if the 1% has a
noticeable complexity cost.

-Alex


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Andreas Leitgeb  
View profile  
 More options Jun 4 2012, 3:34 pm
Newsgroups: comp.lang.tcl
From: Andreas Leitgeb <a...@gamma.logic.tuwien.ac.at>
Date: Mon, 4 Jun 2012 19:34:29 +0000 (UTC)
Local: Mon, Jun 4 2012 3:34 pm
Subject: Re: Matching ']' in glob patterns

I wouldn't care about []], if at least there was [\]] in glob patterns.

"Strict compatibility with shell-globbing" surely isn't all that important,
but being able to include close-brackets in character sets would be really
neat, and the implementation would be quite trivial:

change (in the quoted fossil snippet)
  if ((*pattern == ']') || (*pattern == '\0')) {
to
  if ( (*pattern == '\0') ||
       ( (*pattern == ']') && pattern > firstsetcharpos ) ) {
and set firstsetcharpos to pattern+1 where the open '[' is hit.

Actually, there is another dirty hack for the OP:
   glob {*{[[{}()],]}*}
but that finds a file with both [ and ] in its name twice. ;-)

> In hindsight, 99% compat is okay if the 1% has a
> noticeable complexity cost.

Agree, but does it?

I figure you'll point out documentation now:
 "A ] may be matched by including it as the first character in the set."
That's how bash describes it.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »