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 

IRC nick regexp

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


Joined: 26 Nov 2004
Posts: 436
Location: Manchester, UK

PostPosted: Wed Sep 09, 2009 6:45 am    Post subject: IRC nick regexp Reply with quote

I consistently use the following regexp in my scripts to validate a nick entered with a command, for example !op <nick> to trigger a PUB bind that ops channel users.

Code:

bind PUB o !op procname

proc procname {nick uhost hand chan text} {
  set target [string trim $text]
  if {[regexp -- {^[\x41-\x7D][-\d\x41-\x7D]*$} $target]} {
    # normal code here
  } else {
    # error code here
  }
}


This seems to work fine on the network I frequent but I have never really considered whether it is generally true for a wide range of IRC networks and, as a consequence, my scripts would not function as expected in other circumstances.

Is the regexp generally true or are there common networks that have other rules regarding the characters allowed in a nick?
_________________
I must have had nothing to do
Back to top
View user's profile Send private message
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Wed Sep 09, 2009 12:15 pm    Post subject: Reply with quote

Why do you need a regexp? why not directly use [onchan] on the target?
_________________
Follow me on GitHub

- Opposing

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


Joined: 26 Nov 2004
Posts: 436
Location: Manchester, UK

PostPosted: Wed Sep 09, 2009 1:04 pm    Post subject: Reply with quote

Fair point. Sorry, I seem to have elicited that response due to using an overly simplistic example, though for completeness it would still be reasonable to use both onchan and a nick checking regexp since they communicate to the command user the exact nature of an error.

Suppose I wanted to use a public command to send a network /WHOIS. In this case the target nick does not need to be in the command source channel. The target nick doesn't even need to be online since this would return a RAW 401 or 402 depending on the syntax of the /WHOIS command. In this case it might be useful to validate the target entered by the command user using the regexp.

Same question. Is it generally valid for common IRC networks?
_________________
I must have had nothing to do
Back to top
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Wed Sep 09, 2009 1:42 pm    Post subject: Reply with quote

I'd say that, apart from the nick length, most irc networks atleast adhere to rfc2812, some possibly rfc1459 as well.

rfc1459 wrote:
<nick> ::= <letter> { <letter> | <number> | <special> }
...
<letter> ::= 'a' ... 'z' | 'A' ... 'Z'
<number> ::= '0' ... '9'
<special> ::= '-' | '[' | ']' | '\' | '`' | '^' | '{' | '}'


rfc2812 wrote:
nickname = ( letter / special ) *8( letter / digit / special / "-" )
...
letter = %x41-5A / %x61-7A ; A-Z / a-z
digit = %x30-39 ; 0-9
...
special = %x5B-60 / %x7B-7D
; "[", "]", "\", "`", "_", "^", "{", "|", "}"


As such, your regular expression permits more characters than either rfcs. Mainly, you allow characters such as "; : ? @" in your expression, which are not allowed within a nickname.
_________________
NML_375, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
arfer
Master


Joined: 26 Nov 2004
Posts: 436
Location: Manchester, UK

PostPosted: Wed Sep 09, 2009 2:03 pm    Post subject: Reply with quote

I don't really see that those extra characters are allowed in the regexp pattern

; == \x3B
: == \x3A
? == \x3F
@ == \x40

All of which are outside the range \x41-\x7D
_________________
I must have had nothing to do
Back to top
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Wed Sep 09, 2009 2:11 pm    Post subject: Reply with quote

Darn, you're right!
Must've overlooked that \d in there.. (and way too little coffee today)

As such, your regular expression should be in line with rfc2812 (although not rfc1459). Being rfc2812 the most common standard these days, I'd say it'll work well with most networks (might be worth adding note as to being rfc2812-compliant, if you're worried users will have issues on non-standard servers)
_________________
NML_375, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
arfer
Master


Joined: 26 Nov 2004
Posts: 436
Location: Manchester, UK

PostPosted: Wed Sep 09, 2009 2:16 pm    Post subject: [SOLVED] IRC nick regexp Reply with quote

Heh, OK. Many thanks. Coffee is a necessary tool for coding.
_________________
I must have had nothing to do
Back to top
View user's profile Send private message
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