Sha256: 07cfd5d493449334a52a88e24a81cbf692774c364259caa685c3577de130f092

Contents?: true

Size: 1.13 KB

Versions: 4

Compression:

Stored size: 1.13 KB

Contents

module RegexpExamples
  # Number of times to repeat for Star and Plus repeaters
  TIMES = 2

  # Maximum number of characters returned from a char set, to reduce output spam
  # For example:
  # If MaxGroupResults = 5, then
  # \d = [0, 1, 2, 3, 4]
  MaxGroupResults = 5

  module CharSets
    Lower = Array('a'..'z')
    Upper = Array('A'..'Z')
    Digit = Array('0'..'9')
    Punct = [33..47, 58..64, 91..96, 123..126].map { |r| r.map { |val| val.chr } }.flatten
    Any = Lower | Upper | Digit | Punct
  end

  # Map of special regex characters, to their associated character sets
  BackslashCharMap = {
    'd' => CharSets::Digit,
    'D' => CharSets::Lower | CharSets::Upper | CharSets::Punct,
    'w' => CharSets::Lower | CharSets::Upper | CharSets::Digit | ['_'],
    'W' => CharSets::Punct.reject { |val| val == '_' },
    's' => [' ', "\t", "\n", "\r", "\v", "\f"],
    'S' => CharSets::Any - [' ', "\t", "\n", "\r", "\v", "\f"],

    't' => ["\t"], # tab
    'n' => ["\n"], # new line
    'r' => ["\r"], # carriage return
    'f' => ["\f"], # form feed
    'a' => ["\a"], # alarm
    'v' => ["\v"], # vertical tab
    'e' => ["\e"], # escape
  }
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
regexp-examples-0.2.0 lib/regexp-examples/constants.rb
regexp-examples-0.1.0 lib/regexp-examples/constants.rb
regexp-examples-0.0.2 lib/regexp-examples/constants.rb
regexp-examples-0.0.1 lib/regexp-examples/constants.rb