egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

matching '*' and '?' as literal chars [SOLVED]

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
TCL_no_TK
Owner


Joined: 25 Aug 2006
Posts: 509
Location: England, Yorkshire

PostPosted: Tue Oct 14, 2008 11:28 pm    Post subject: matching '*' and '?' as literal chars [SOLVED] Reply with quote

I've tryed using string match, but it seems to allow 'anything' as '*' (as expected). Anyone know of a way to do this, please? Smile
_________________
TCL the misunderstood


Last edited by TCL_no_TK on Thu Oct 16, 2008 10:56 pm; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail
user
 


Joined: 18 Mar 2003
Posts: 1452
Location: Norway

PostPosted: Wed Oct 15, 2008 5:04 am    Post subject: Reply with quote

Code:
string match \\*\\? *?

_________________
Have you ever read "The Manual"?
Back to top
View user's profile Send private message
TCL_no_TK
Owner


Joined: 25 Aug 2006
Posts: 509
Location: England, Yorkshire

PostPosted: Wed Oct 15, 2008 3:52 pm    Post subject: Reply with quote

Tryed it but got this:
Quote:
[08:47:57] <Me> .tcl string match {\\*\\? *?} *!*@two*.many?.wild*.car?ds.fr
[08:47:57] <Bot> Tcl: 0
[08:48:13] <Me> .tcl string match "\\*\\? *?" "*!*@two*.many?.wild*.car?ds.fr"
[08:48:13] <Bot> Tcl: 0
[08:48:27] <Me> .tcl regexp -all -- "\\*\\? *?" "*!*@two*.many?.wild*.car?ds.fr"
[08:48:27] <Bot> Tcl: 0
[08:48:37] <Me> .tcl regexp -all -- {(\\*\\?|*?)} "*!*@two*.many?.wild*.car?ds.fr"
[08:48:37] <Bot> Tcl error: couldn't compile regular expression pattern: quantifier operand invalid
[08:48:56] <Me> .tcl string match "\\*\\? *?" "*"
[08:48:56] <Bot> Tcl: 0
[08:48:58] <Me> .tcl string match "\\*\\? *?" "*?"
[08:48:58] <Bot> Tcl: 0
[08:48:59] <Me> .tcl string match "\\*\\? *?" "* ?"
[08:48:59] <Bot> Tcl: 0
[08:49:02] <Me> .tcl string match "\\*\\? *?" "?"
[08:49:02] <Bot> Tcl: 0
[08:49:18] <Me> .tcl regexp -all -- {(\\*|\\?)} "*!*@two*.many?.wild*.car?ds.fr"
[08:49:18] <Bot> Tcl: 30
[08:49:27] <Me> .tcl regexp -all -- {(\\*|\\?)} "*!*@*.fr"
[08:49:27] <Bot> Tcl: 8
Played around a bit and tryed MC_8's filter from more tools, which dose the same thing you gave me. However, its not returning the number of matches
Quote:
[09:55:04] <Me> .tcl set wd_fil1 [filter -regexp "?"]
[09:55:04] <bot> Tcl: \?
[09:55:08] <Me> .tcl set wd_fil2 [filter -regexp "*"]
[09:55:08] <bot> Tcl: \*
[09:55:26] <Me> .tcl regexp -all -- {[$wd_fil2]} "*!*@*.fr"
[09:55:26] <bot> Tcl: 1
[09:56:39] <Me> .tcl regexp -all -- {([$wd_fil1]|[$wd_fil2])} "*!*@*.fr ?"
[09:56:39] <bot> Tcl: 1
[09:56:41] <Me> .tcl regexp -all -- {([$wd_fil1]|[$wd_fil2])} "*!*@*.fr ? *"
[09:56:41] <bot> Tcl: 1
Neutral
_________________
TCL the misunderstood
Back to top
View user's profile Send private message Send e-mail
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Wed Oct 15, 2008 5:06 pm    Post subject: Reply with quote

When you add escape characters to * and ? it means they'll be treated as characters instead of wild cards. When you use "\\* \\?" as match pattern then it will only match "* ?" and nothing else (common sense). What you're probably looking for is something like
Code:
string match "*\\**\\?*" $string

This will match a string containing '*' followed by '?' anywhere in a string ('*' and '?' don't necessary have to follow each other). Example
Quote:
% string match "*\\**\\?*" *!*@two*.many?.wild*.car?ds.fr
1


Edit: If you want to count the number of '*' and '?' in a string then you should use [regexp] (it's not possible with [string match]). For example
Code:
regexp -all {\?} $string ; # returns number of '?' in string
regexp -all {\*} $string ; # returns number of '*' in string

_________________
Follow me on GitHub

- Opposing

Public Tcl scripts
Back to top
View user's profile Send private message Visit poster's website
TCL_no_TK
Owner


Joined: 25 Aug 2006
Posts: 509
Location: England, Yorkshire

PostPosted: Thu Oct 16, 2008 10:56 pm    Post subject: Reply with quote

Thanks Very Happy
_________________
TCL the misunderstood
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber