Parent

Namespace

Class/Module Index [+]

Quicksearch

Regexp

We extend the Regexp class with an Irc module which will contain some Irc-specific regexps


Extensions to the Regexp class, with some common and/or complex regular expressions.


First of all we add a method to the Regexp class

Constants

DEC_IP_ADDR
DEC_OCTET
DIGITS

We start with some general-purpose ones which will be used in the Irc module too, but are useful regardless

HEX_16BIT

IPv6, from Resolv::IPv6, without the A..z anchors

HEX_DIGIT
HEX_DIGITS
HEX_IP_ADDR
HEX_OCTET
IN_ON
IP6_6Hex4Dec
IP6_8Hex
IP6_ADDR
IP6_CompressedHex
IP6_CompressedHex4Dec
IP_ADDR

Public Class Methods

new_list(reg, pfx = "") click to toggle source

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.

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

Public Instance Methods

has_captures?() click to toggle source

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

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

The MessageMapper cleanup method: does both remove_capture and remove_head_tail

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

We may want to remove captures

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

We may want to remove head and tail anchors

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

[Validate]

Generated with the Darkfish Rdoc Generator 2.