Code: Select all
if {[string length [regsub -all {[^0-9]} $nick ""]] > 6} {
# do whatever
}
Code: Select all
if {[regexp -all {[0-9]} $nick] > 6} {
do whatever here
}
Code: Select all
if {[string length [regsub -all {[^0-9]} $nick ""]] > 6} {
# do whatever
}
Code: Select all
% set text "f2A94d"
f2A94d
% regsub -all {[^0-9]} $text ""
294
% join [regexp -all -inline -- {[0-9]+} $text] ""
294
% join [regexp -all -inline -- {\d+} $text] ""
294
% foreach e [split $text ""] {
if {[string is integer $e]} {
append result $e
}
}
% puts $result
294
Code: Select all
% time { regsub -all {[^0-9]} $text "" } 1000
3.553 microseconds per iteration
% time { join [regexp -all -inline -- {\d+} $text] "" } 1000
3.457 microseconds per iteration
% time { join [regexp -all -inline -- {[0-9]+} $text] "" } 1000
3.939 microseconds per iteration
% time { foreach e [split $text ""] { if {[string is integer $e]} { append result $e } } } 1000
10.051 microseconds per iteration
% time { foreach e [split $text ""] { if {[string is integer $e]} { append result $e } } } 1000
8.604 microseconds per iteration
% time { foreach e [split $text ""] { if {[string is integer $e]} { append result $e } } } 1000
9.156 microseconds per iteration
% time { foreach e [split $text ""] { if {[string is integer $e]} { append result $e } } } 1000
6.549 microseconds per iteration
% time { foreach e [split $text ""] { if {[string is integer $e]} { append result $e } } } 1000
9.37 microseconds per iteration
Code: Select all
% time { regsub -all {[^0-9]} $text "" } 10000
2.5413 microseconds per iteration
% time { join [regexp -all -inline -- {\d+} $text] "" } 10000
2.7552 microseconds per iteration
Code: Select all
% foreach e [split $text ""] {
if {[scan $e {%d} no] > 0} {
append result $e
}
}
% puts $result
294
Code: Select all
% time { unset result; foreach e [split $text ""] { if {[scan $e {%d} no] > 0} { append result $e} } } 1000
11.501 microseconds per iteration
% time { unset result; foreach e [split $text ""] { if {[scan $e {%d} no] > 0} { append result $e} } } 1000
13.495 microseconds per iteration
% time { unset result; foreach e [split $text ""] { if {[scan $e {%d} no] > 0} { append result $e} } } 1000
13.228 microseconds per iteration
Code: Select all
if {[regexp -all {[0-9]} $nick] > 6} {
#do whatever here
}
but we wanted to count the digits in the nick to check for amount of digitsthat removes any character that isn't in the 0 to 9 range and then returns it's length.
Code: Select all
if {[string length [regsub -all {[^0-9]} $nick ""]] > 6} {
# do whatever
}
Code: Select all
% set nick "f2A94d"
f2A94d
% regsub -all {[^0-9]} $nick ""
294
% string length [regsub -all {[^0-9]} $nick ""]
3
% set nick "aaaa3db4"
aaaa3db4
% string length [regsub -all {[^0-9]} $nick ""]
2