This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Matching strings containing []

Old posts that have not been replied to for several years.
Locked
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Matching strings containing []

Post by Sir_Fz »

I have a problem in a script that matches nicks joining channels with nicks in a file, if 1 is returned the bot will kick the nick. I'm using string match -nocase $nick-from-file $nick but if the nick contains [ or ] in it, tcl considers it a command. Is there any way to fix this ?
User avatar
user
 
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

http://forum.egghelp.org/viewtopic.php?t=5974 - read your own post and my reply. :wink:
Have you ever read "The Manual"?
User avatar
GodOfSuicide
Master
Posts: 463
Joined: Mon Jun 17, 2002 8:00 pm
Location: Austria

Post by GodOfSuicide »

somehow this question is a classic quote...some kind of tradition

(again a strong candidate for a sticky tread (not the post, the topic))
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

thanks user for pointing that out. you said "Use 'string equal'" in your post there but it does the same thing on nicks containing such characters. I would use ==, but I want to use wildcards such as * and ? in matching.
User avatar
user
 
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

Sir_Fz wrote:thanks user for pointing that out. you said "Use 'string equal'" in your post there but it does the same thing on nicks containing such characters. I would use ==, but I want to use wildcards such as * and ? in matching.
The brackets doesn't trigger command substitution when used in a mask passed to 'string match' or as one of the strings being compared using 'string equal'. What exactly are you doing? You might also want to check the manual page for string match (to know what chars are special so you know what to escape in your masks)
Have you ever read "The Manual"?
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

I've tested string qual using .tcl command in partyline, for example .tcl string equal -nocase [nick1] [Nick1] it returns "Tcl error: invalid command name "nick1"". the pattern here would be the nick from the file (I use foreach to get each nick from the file) and the string would be the nick joining the channel, would string equal be the solution ?
Last edited by Sir_Fz on Wed Dec 03, 2003 4:18 pm, edited 1 time in total.
User avatar
user
 
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

Sir_Fz wrote:I've tested string qual using .tcl command in partyline, for example .tcl string equal -nocase [nick1] [Nick1] it returns "Tcl error: invalid command name "nick1"". the pattern here would be the nick from the file (I use foreach to get each nick from the file) and the string would be the nick joining the channel, would string equal be the solution ?
The line you run using .tcl in your eggdrop is evaluated and variable/command/backslash substitution is done. (escaping is needed if you don't want this to happen)
Text recieved from irc/read from a file and put in a variable is not evaluated. (no escaping needed)

'string equal' is just a simple char by char comparison of the strings (optional -nocase), so if you want the match chars * and ? to work you better use 'string match' and escape the special chars you don't want to work using 'regsub' or 'string map'.

Code: Select all

proc yourMatch {mask string} {
  string match -nocase [string map {\\ \\\\ \[ \\\[ \] \\\]} $mask] $string
}
Have you ever read "The Manual"?
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

Thanx, that works perfectly :)

I guess string map is faster the regsub right ?
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Evidently.. in my tests the string stuff are a lot faster than an regsub. Do a lil test on yourself.
Once the game is over, the king and the pawn go back in the same box.
Locked