Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How can I use "-nocase" with "-regexp" in a SWITCH statement

5 views
Skip to first unread message

Robert Stovall

unread,
Dec 18, 2001, 5:10:39 PM12/18/01
to
I'm trying to create a switch statement using -regexp option and need
-nocase option for regexp enabled.


EX of hard way:
switch -regexp -- "StrInG" {
[sS][Tt][Rr][Ii][Nn][gG] { puts "Found string using upper/lower string
sqare braces"}
}

Should be able to use regular expressions '-nocase' option instead and
do something like
regexp -nocase {string} StrInG inside the switch statement??????? HOW?

robert.stovall.vcf

Lorne

unread,
Dec 18, 2001, 5:56:20 PM12/18/01
to
On Tue, 18 Dec 2001 16:10:39 -0600, Robert Stovall
<robert....@windriver.com> wrote:

>I'm trying to create a switch statement using -regexp option and need
>-nocase option for regexp enabled.
>

>switch -regexp -- "StrInG" {
> [sS][Tt][Rr][Ii][Nn][gG] { puts "Found string using upper/lower string
>sqare braces"}
>}
>
>Should be able to use regular expressions '-nocase' option instead and
>do something like
>regexp -nocase {string} StrInG inside the switch statement??????? HOW?

set str "StRiNg"
switch -regexp -- [string tolower $str] {
string {puts "found a string"}
}

Jeff Hobbs

unread,
Dec 18, 2001, 6:24:15 PM12/18/01
to
Robert Stovall wrote:
>
> I'm trying to create a switch statement using -regexp option and need
> -nocase option for regexp enabled.
>
> EX of hard way:
> switch -regexp -- "StrInG" {
> [sS][Tt][Rr][Ii][Nn][gG] { puts "Found string using upper/lower string
> sqare braces"}
> }

regexps have built-in option handling, so just do:

switch -regexp -- $string {
"(?i)string" { ... }

However, it might be a little faster and easier to do just:

switch -exact -- [string tolower $string] {
"string" { ... }

--
Jeff Hobbs The Tcl Guy
Senior Developer http://www.ActiveState.com/
Tcl Support and Productivity Solutions
http://www.ActiveState.com/Products/ASPN_Tcl/

0 new messages