Sha256: 040a5e76cfd0dc794083dbfe7983ec6f7b0009bd0e1833b90c8781fff3c89a82

Contents?: true

Size: 1.43 KB

Versions: 6

Compression:

Stored size: 1.43 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')
    # 45.chr = "-". Need to make sure this is at the START of the array, or things break
    # This is because of the /[a-z]/ regex syntax, and how it's being parsed
    Punct = [45..45, 33..44, 46..47, 58..64, 91..96, 123..126].map { |r| r.map { |val| val.chr } }.flatten
    Hex   = Array('a'..'f') | Array('A'..'F') | Digit
    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"],
    'h' => CharSets::Hex,
    'H' => CharSets::Any - CharSets::Hex,

    '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

6 entries across 6 versions & 1 rubygems

Version Path
regexp-examples-0.3.1 lib/regexp-examples/constants.rb
regexp-examples-0.3.0 lib/regexp-examples/constants.rb
regexp-examples-0.2.4 lib/regexp-examples/constants.rb
regexp-examples-0.2.3 lib/regexp-examples/constants.rb
regexp-examples-0.2.2 lib/regexp-examples/constants.rb
regexp-examples-0.2.1 lib/regexp-examples/constants.rb