Class Regexp
In: lib/rbot/irc.rb
lib/rbot/core/utils/extends.rb
lib/rbot/messagemapper.rb
Parent: Object
BasicUserMessage JoinMessage NamesMessage WhoisMessage ModeChangeMessage KickMessage MotdMessage QuitMessage BanlistMessage UserMessage NoSuchTargetMessage TopicMessage NickMessage WelcomeMessage UnknownMessage InviteMessage PartMessage NetmaskList UserList ArrayOf ChannelList Netmask User\n[lib/rbot/botuser.rb\nlib/rbot/irc.rb] Channel Singleton RfcCasemap StrictRfcCasemap AsciiCasemap Casemap PrivMessage NoticeMessage TokyoCabinet::BDB CIBDB Btree CIBtree Socket MessageQueue QueueRing Client DBHash\n[lib/rbot/registry/bdb.rb\nlib/rbot/registry/tc.rb] DBTree\n[lib/rbot/registry/bdb.rb\nlib/rbot/registry/tc.rb] Server NetmaskDb Bot\n[lib/rbot/botuser.rb\nlib/rbot/config.rb\nlib/rbot/ircbot.rb\nlib/rbot/language.rb\nlib/rbot/message.rb\nlib/rbot/messagemapper.rb\nlib/rbot/plugins.rb\nlib/rbot/rbotconfig.rb\nlib/rbot/registry/bdb.rb\nlib/rbot/registry/tc.rb] Regexp\n[lib/rbot/core/utils/extends.rb\nlib/rbot/irc.rb\nlib/rbot/messagemapper.rb] lib/rbot/ircsocket.rb lib/rbot/rfc2812.rb lib/rbot/registry/tc.rb lib/rbot/irc.rb lib/rbot/maskdb.rb lib/rbot/message.rb lib/rbot/messagemapper.rb lib/rbot/botuser.rb lib/rbot/registry/tc.rb (null) BotConfig PKGConfig ServerOrCasemap Irc dot/f_35.png

First of all we add a method to the Regexp class

Methods

Classes and Modules

Module Regexp::Irc

Constants

DIGITS = /\d+/   We start with some general-purpose ones which will be used in the Irc module too, but are useful regardless
HEX_DIGIT = /[0-9A-Fa-f]/
HEX_DIGITS = /#{HEX_DIGIT}+/
HEX_OCTET = /#{HEX_DIGIT}#{HEX_DIGIT}?/
DEC_OCTET = /[01]?\d?\d|2[0-4]\d|25[0-5]/
DEC_IP_ADDR = /#{DEC_OCTET}\.#{DEC_OCTET}\.#{DEC_OCTET}\.#{DEC_OCTET}/
HEX_IP_ADDR = /#{HEX_OCTET}\.#{HEX_OCTET}\.#{HEX_OCTET}\.#{HEX_OCTET}/
IP_ADDR = /#{DEC_IP_ADDR}|#{HEX_IP_ADDR}/
HEX_16BIT = /#{HEX_DIGIT}{1,4}/   IPv6, from Resolv::IPv6, without the \A..\z anchors
IP6_8Hex = /(?:#{HEX_16BIT}:){7}#{HEX_16BIT}/
IP6_CompressedHex = /((?:#{HEX_16BIT}(?::#{HEX_16BIT})*)?)::((?:#{HEX_16BIT}(?::#{HEX_16BIT})*)?)/
IP6_6Hex4Dec = /((?:#{HEX_16BIT}:){6,6})#{DEC_IP_ADDR}/
IP6_CompressedHex4Dec = /((?:#{HEX_16BIT}(?::#{HEX_16BIT})*)?)::((?:#{HEX_16BIT}:)*)#{DEC_IP_ADDR}/
IP6_ADDR = /(?:#{IP6_8Hex})|(?:#{IP6_CompressedHex})|(?:#{IP6_6Hex4Dec})|(?:#{IP6_CompressedHex4Dec})/
IN_ON = /in|on/

Public Class methods

A method to build a regexp that matches a list of something separated by optional commas and/or the word "and", an optionally repeated prefix, and whitespace.

[Source]

     # File lib/rbot/core/utils/extends.rb, line 373
373:   def Regexp.new_list(reg, pfx = "")
374:     if pfx.kind_of?(String) and pfx.empty?
375:       return %r(#{reg}(?:,?(?:\s+and)?\s+#{reg})*)
376:     else
377:       return %r(#{reg}(?:,?(?:\s+and)?(?:\s+#{pfx})?\s+#{reg})*)
378:     end
379:   end

Public Instance methods

a Regexp has captures when its source has open parenthesis which are preceded by an even number of slashes and not followed by a question mark

[Source]

   # File lib/rbot/messagemapper.rb, line 7
7:   def has_captures?
8:     self.source.match(/(?:^|[^\\])(?:\\\\)*\([^?]/)
9:   end

The MessageMapper cleanup method: does both remove_capture and remove_head_tail

[Source]

    # File lib/rbot/messagemapper.rb, line 27
27:   def mm_cleanup
28:     new = self.source.gsub(/(^|[^\\])((?:\\\\)*)\(([^?])/) {
29:       "%s%s(?:%s" % [$1, $2, $3]
30:     }.sub(/^\^/,'').sub(/\$$/,'')
31:     Regexp.new(new, self.options)
32:   end

We may want to remove captures

[Source]

    # File lib/rbot/messagemapper.rb, line 12
12:   def remove_captures
13:     new = self.source.gsub(/(^|[^\\])((?:\\\\)*)\(([^?])/) {
14:       "%s%s(?:%s" % [$1, $2, $3]
15:     }
16:     Regexp.new(new, self.options)
17:   end

We may want to remove head and tail anchors

[Source]

    # File lib/rbot/messagemapper.rb, line 20
20:   def remove_head_tail
21:     new = self.source.sub(/^\^/,'').sub(/\$$/,'')
22:     Regexp.new(new, self.options)
23:   end

[Validate]