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.

regexp check

Old posts that have not been replied to for several years.
Locked
User avatar
Alchera
Revered One
Posts: 3344
Joined: Mon Aug 11, 2003 12:42 pm
Location: Ballarat Victoria, Australia
Contact:

regexp check

Post by Alchera »

I'm not that good with regexp but have this line of code and am wondering whether it could be done better. The aim being to exclude adding users to the bot with either [] or {} in their nick(s).

Code: Select all

if {[regexp -nocase -- {[\[\]\{\}\]]+} $text]} {sendcmd "privmsg $chan :Illegal characters in nick: \[\]\ \{\}\ ";return}
The above does work very well btw. :)

The "sendcmd" procedure is a custom one of mine.
Add [SOLVED] to the thread title if your issue has been.
Search | FAQ | RTM
User avatar
awyeah
Revered One
Posts: 1580
Joined: Mon Apr 26, 2004 2:37 am
Location: Switzerland
Contact:

Post by awyeah »

Well you can use string match as well Alchera if you don't want to add users in the bot which have [ ] { } in their nicks.

Code: Select all

if {([string match "*\[*\]*" $text]) || ([string match "*\{*\}*" $text])} { sendcmd "PRIVMSG $chan :Illegal characters in nick: \[\]\ \{\}\ "; return 0 }
Alternatively, you can also do a foreach loop and assign a list to the characters you want to exempt *\[*\]* *\{*\}* bla bla and then do a string match for each character if you don't want to use the || function.

I am not sure, but I think || (OR) will be faster than running the loop if I am correct. (faster in milli/nano seconds, heh)

regexp only matches for complex structures here the one you are using is not complex and quite simple. Furthermore regexp is quite slower than string match (has been proved on the forum), so I suggest you use string match here! :P
·­awyeah·

==================================
Facebook: jawad@idsia.ch (Jay Dee)
PS: Guys, I don't accept script helps or requests personally anymore.
==================================
User avatar
awyeah
Revered One
Posts: 1580
Joined: Mon Apr 26, 2004 2:37 am
Location: Switzerland
Contact:

Post by awyeah »

By the way I forgot to mention:

Code: Select all

if {([string match "*\[*\]*" $text]) || ([string match "*\{*\}*" $text])} { sendcmd "PRIVMSG $chan :Illegal characters in nick: \[\]\ \{\}\ "; return 0 } 
Will match nicks like:
- aw[ye]ah
- Al[cher]a
- awe{so}me
- [p][r][n][c][e]
- a{s}s{k}i{c}k{e}r
- aw[[y]]eah etc...

If you only want to match nicks like:
- [awyeah]
- {Alchera}
- [elite] and etc...

You will need to use something like:

Code: Select all

if {(([string equal "\[" [string index $nick 0]) && ([string equal "\]" [string index [expr [string length $nick] - 1]]])) || (([string equal "\{" [string index $nick 0]) && ([string equal "\}" [string index [expr [string length $nick] - 1]]]))} { sendcmd "PRIVMSG $chan :Illegal characters in nick: \[\]\ \{\}\ "; return 0 }
Meaning you have to check the first and last characters of the nick by using string index. If the first and last character of the nick equals to [ and ] or { and } then you can go ahead and do your stuff.
·­awyeah·

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