View previous topic :: View next topic |
Author |
Message |
simo Owner
Joined: 22 Mar 2015 Posts: 969
|
Posted: Wed Dec 07, 2016 1:23 pm Post subject: detect nicks with excessive digits in it |
|
|
is it possible to have tcl check for digits like more than 6 digits anywhere in the nick
Last edited by simo on Sun Mar 03, 2019 12:25 pm; edited 1 time in total |
|
Back to top |
|
 |
caesar Mint Rubber

Joined: 14 Oct 2001 Posts: 3743 Location: Mint Factory
|
Posted: Thu Dec 08, 2016 2:09 am Post subject: |
|
|
Code: |
if {[string length [regsub -all {[^0-9]} $nick ""]] > 6} {
# do whatever
}
|
_________________ Once the game is over, the king and the pawn go back in the same box. |
|
Back to top |
|
 |
simo Owner
Joined: 22 Mar 2015 Posts: 969
|
Posted: Thu Dec 08, 2016 4:43 pm Post subject: |
|
|
tested it and works fine thnx caesar |
|
Back to top |
|
 |
simo Owner
Joined: 22 Mar 2015 Posts: 969
|
Posted: Thu Jun 04, 2020 11:17 pm Post subject: |
|
|
its old topic but i tried this one again and it seems it counts general chars lenght and not the amount of digits anywhere in the nick |
|
Back to top |
|
 |
simo Owner
Joined: 22 Mar 2015 Posts: 969
|
Posted: Thu Jun 04, 2020 11:42 pm Post subject: |
|
|
i tried this
Code: |
if {[regexp -all {[0-9]} $nick] > 6} {
do whatever here
}
|
it does seem to work not sure if its proper and not sure if its fastest ? since from what i keep hearing is regexp might not be the fastest to process |
|
Back to top |
|
 |
caesar Mint Rubber

Joined: 14 Oct 2001 Posts: 3743 Location: Mint Factory
|
Posted: Fri Jun 05, 2020 1:27 am Post subject: |
|
|
The code you mentioned returns the digits from the string, not it's length, hence why i suggested the initial code:
Code: |
if {[string length [regsub -all {[^0-9]} $nick ""]] > 6} {
# do whatever
}
|
that removes any character that isn't in the 0 to 9 range and then returns it's length.
Anyway, there are 3 options to get the digits from a string:
1. regsub
2. regexp
3. split, loop and compare
Code: |
% 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
|
Now, if you want to see who's faster, or if you wonder if that regsub is slow:
Code: |
% 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
|
Right off the bat we see two possible candidates, so we try again with 10000 times:
Code: |
% 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
|
Hope this answers your question.
Edit: We can use scan instead of string is integer
Code: |
% foreach e [split $text ""] {
if {[scan $e {%d} no] > 0} {
append result $e
}
}
% puts $result
294
|
but given that it's a loop will still take a lot longer than regsub or regexp:
Code: |
% 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
|
Edit: Actually the code you tried:
Code: |
if {[regexp -all {[0-9]} $nick] > 6} {
#do whatever here
}
|
returns the length of digits from 0 to 9 it finds in $nick variable. Duno at what was looking at when did the initial test. /facepalm _________________ Once the game is over, the king and the pawn go back in the same box.
Last edited by caesar on Mon Jun 22, 2020 1:22 am; edited 1 time in total |
|
Back to top |
|
 |
simo Owner
Joined: 22 Mar 2015 Posts: 969
|
Posted: Fri Jun 05, 2020 1:31 pm Post subject: |
|
|
Quote: |
that removes any character that isn't in the 0 to 9 range and then returns it's length.
|
but we wanted to count the digits in the nick to check for amount of digits
as this seems to count the length of the nick and not the amount of digits in it:
Code: |
if {[string length [regsub -all {[^0-9]} $nick ""]] > 6} {
# do whatever
}
|
|
|
Back to top |
|
 |
caesar Mint Rubber

Joined: 14 Oct 2001 Posts: 3743 Location: Mint Factory
|
Posted: Sat Jun 06, 2020 3:23 am Post subject: |
|
|
Code: |
% 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
|
isn't this what you where looking for? _________________ Once the game is over, the king and the pawn go back in the same box. |
|
Back to top |
|
 |
simo Owner
Joined: 22 Mar 2015 Posts: 969
|
Posted: Sat Jun 06, 2020 8:39 am Post subject: |
|
|
im not sure what that does ceasar but what we was looking for was to count digits in nick and if exceeding like 6 or higher to take action |
|
Back to top |
|
 |
simo Owner
Joined: 22 Mar 2015 Posts: 969
|
Posted: Sat Jun 06, 2020 10:34 am Post subject: |
|
|
tested it again seems to work now |
|
Back to top |
|
 |
CrazyCat Revered One

Joined: 13 Jan 2002 Posts: 1057 Location: France
|
Posted: Sun Jun 07, 2020 5:58 pm Post subject: |
|
|
simo wrote: | im not sure what that does ceasar but what we was looking for was to count digits in nick and if exceeding like 6 or higher to take action |
What does ceasar is quite simple: he replaces all characters which are not between 0 to 9 with nothing and count the length of the resulting string. _________________ https://www.eggdrop.fr - French IRC network
Offer me a coffee - Do not ask me help in PM, we are a community. |
|
Back to top |
|
 |
simo Owner
Joined: 22 Mar 2015 Posts: 969
|
Posted: Sun Jun 07, 2020 10:55 pm Post subject: |
|
|
Tnx crazycat after taking a look again i saw its working and its exactly what was desired another fine job from caesar tnx again caesar much appreciated as always |
|
Back to top |
|
 |
|