Derek Karpinski
November 6th, 2012, 03:05 AM
I've been using tcl for awhile now. Nothing super fancy, mostly low-grade stuff. I'm always wanting to learn something new, and try things different ways.
So, my question:
suppose a variable 'test' that can be any value from 1-29.
I want to check for it's value and steer my logic depending on it's value. I want to check if the value is one of the following:
0, 1, 3, or 24.
I accomplished this with:
switch $test {
0 {do stuff}
1 {do stuff}
3 {do stuff}
24 {do stuff}
default {do other stuffs}
}
Problem solved...........
But I want to learn regular expressions a bit more. So I tried:
if { [regexp {[0]|[1]|[3]|[24]} $test] == 1} {
do stuff
} else {
do other stuffs
}
But my regex is not working. It matches a 2. I need it to match any one of those numbers (0, 1, 3, or 24) and the whole number only.
What am I doing wrong?
So, my question:
suppose a variable 'test' that can be any value from 1-29.
I want to check for it's value and steer my logic depending on it's value. I want to check if the value is one of the following:
0, 1, 3, or 24.
I accomplished this with:
switch $test {
0 {do stuff}
1 {do stuff}
3 {do stuff}
24 {do stuff}
default {do other stuffs}
}
Problem solved...........
But I want to learn regular expressions a bit more. So I tried:
if { [regexp {[0]|[1]|[3]|[24]} $test] == 1} {
do stuff
} else {
do other stuffs
}
But my regex is not working. It matches a 2. I need it to match any one of those numbers (0, 1, 3, or 24) and the whole number only.
What am I doing wrong?