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.

Problem with string match.

Old posts that have not been replied to for several years.
Locked
User avatar
awyeah
Revered One
Posts: 1580
Joined: Mon Apr 26, 2004 2:37 am
Location: Switzerland
Contact:

Problem with string match.

Post by awyeah »

Hi,

I have this small piece of code, I am trying to detect if a variable $banlistremove has any number, from like the 0 to 9 range, 0, 1, 2, 3......, 9, 0 in it, or not. :)

Code: Select all

  if {(([string match *[0-9]* $banlistremove]) || ([string match *[0-9][0-9]* $banlistremove])) && (![string equal -nocase $banlistremove "all"])} { banlist:clean:specific $chan }
But it, gives me an error. :o

Code: Select all

[03:35] Tcl error [banlist:type]: invalid command name "0-9"
I have also tried "*[0-9]*", with quotations, but doesn't work. :(
What could be the reason? :roll:
·­awyeah·

==================================
Facebook: jawad@idsia.ch (Jay Dee)
PS: Guys, I don't accept script helps or requests personally anymore.
==================================
g
greenbear
Owner
Posts: 733
Joined: Mon Sep 24, 2001 8:00 pm
Location: Norway

Post by greenbear »

Just escape the brackets and it should work

Code: Select all

string match *\[0-9\]* $banlistremove
User avatar
awyeah
Revered One
Posts: 1580
Joined: Mon Apr 26, 2004 2:37 am
Location: Switzerland
Contact:

Post by awyeah »

Ah thanks alot gb. :wink:
I am not sure why it didnt work without the \'s.

Because with regexp, regsub you can use [0-9] or [A-Z] directly. :roll:
My mistake I guess. :mrgreen:
·­awyeah·

==================================
Facebook: jawad@idsia.ch (Jay Dee)
PS: Guys, I don't accept script helps or requests personally anymore.
==================================
D
DayCuts
Voice
Posts: 37
Joined: Tue Jun 15, 2004 8:43 am

Post by DayCuts »

Because special charactors such as [ and ] have different meanings in refular expression. Also i tend to put any regular expression inside {} brackets to avoid any clashes with tcl interpretations of anything.

[]'s in general tcl code are treated as a command. a \ before a special charactor (such as those []'s) is an 'escape'. Basically tells the tcl engine to treat the proceeding charactor as plain text and not interpret it as a special charactor like it normally would.
User avatar
awyeah
Revered One
Posts: 1580
Joined: Mon Apr 26, 2004 2:37 am
Location: Switzerland
Contact:

Post by awyeah »

Yeah, thanks I am familiar with the last paragraph.
I myself, use { } braces when using regexp or regsub.
·­awyeah·

==================================
Facebook: jawad@idsia.ch (Jay Dee)
PS: Guys, I don't accept script helps or requests personally anymore.
==================================
Locked