| View previous topic :: View next topic |
| Author |
Message |
arfer Master

Joined: 26 Nov 2004 Posts: 436 Location: Manchester, UK
|
Posted: Wed Sep 09, 2009 6:45 am Post subject: IRC nick regexp |
|
|
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 |
|
 |
Sir_Fz Revered One

Joined: 27 Apr 2003 Posts: 3793 Location: Lebanon
|
Posted: Wed Sep 09, 2009 12:15 pm Post subject: |
|
|
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 |
|
 |
arfer Master

Joined: 26 Nov 2004 Posts: 436 Location: Manchester, UK
|
Posted: Wed Sep 09, 2009 1:04 pm Post subject: |
|
|
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 |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Wed Sep 09, 2009 1:42 pm Post subject: |
|
|
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 |
|
 |
arfer Master

Joined: 26 Nov 2004 Posts: 436 Location: Manchester, UK
|
Posted: Wed Sep 09, 2009 2:03 pm Post subject: |
|
|
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 |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Wed Sep 09, 2009 2:11 pm Post subject: |
|
|
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 |
|
 |
arfer Master

Joined: 26 Nov 2004 Posts: 436 Location: Manchester, UK
|
Posted: Wed Sep 09, 2009 2:16 pm Post subject: [SOLVED] IRC nick regexp |
|
|
Heh, OK. Many thanks. Coffee is a necessary tool for coding. _________________ I must have had nothing to do |
|
| Back to top |
|
 |
|