| View previous topic :: View next topic |
| Author |
Message |
TCL_no_TK Owner

Joined: 25 Aug 2006 Posts: 509 Location: England, Yorkshire
|
Posted: Tue Oct 14, 2008 11:28 pm Post subject: matching '*' and '?' as literal chars [SOLVED] |
|
|
I've tryed using string match, but it seems to allow 'anything' as '*' (as expected). Anyone know of a way to do this, please?  _________________ 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 |
|
 |
user

Joined: 18 Mar 2003 Posts: 1452 Location: Norway
|
Posted: Wed Oct 15, 2008 5:04 am Post subject: |
|
|
| Code: | | string match \\*\\? *? |
_________________ Have you ever read "The Manual"? |
|
| Back to top |
|
 |
TCL_no_TK Owner

Joined: 25 Aug 2006 Posts: 509 Location: England, Yorkshire
|
Posted: Wed Oct 15, 2008 3:52 pm Post subject: |
|
|
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 |  _________________ TCL the misunderstood |
|
| Back to top |
|
 |
Sir_Fz Revered One

Joined: 27 Apr 2003 Posts: 3793 Location: Lebanon
|
Posted: Wed Oct 15, 2008 5:06 pm Post subject: |
|
|
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 |
|
 |
TCL_no_TK Owner

Joined: 25 Aug 2006 Posts: 509 Location: England, Yorkshire
|
|
| Back to top |
|
 |
|