module ERegex
Regex Module
Constants
- PATTERN_ALPHA
- PATTERN_ALPHADASH
- PATTERN_ALPHANUMERIC
- PATTERN_DIGITS
- PATTERN_EMAIL
- PATTERN_NUMERIC
- PATTERN_UUID
- VERSION
Public Class Methods
alpha(subject, replace = "")
click to toggle source
# File lib/eregex.rb, line 45 def self.alpha(subject, replace = "") self.replace(subject, self::PATTERN_ALPHA, replace) end
alpha?(subject, allow_whitespace: false)
click to toggle source
# File lib/eregex.rb, line 17 def self.alpha?(subject, allow_whitespace: false) match(subject, self::PATTERN_ALPHA, allow_whitespace: allow_whitespace) end
alphadash(subject, replace = "")
click to toggle source
# File lib/eregex.rb, line 49 def self.alphadash(subject, replace = "") self.replace(subject, self::PATTERN_ALPHADASH, replace) end
alphadash?(subject, allow_whitespace: false)
click to toggle source
# File lib/eregex.rb, line 21 def self.alphadash?(subject, allow_whitespace: false) match(subject, self::PATTERN_ALPHADASH, allow_whitespace: allow_whitespace) end
alphanumeric(subject, replace = "")
click to toggle source
# File lib/eregex.rb, line 53 def self.alphanumeric(subject, replace = "") self.replace(subject, self::PATTERN_ALPHANUMERIC, replace) end
alphanumeric?(subject, allow_whitespace: false)
click to toggle source
# File lib/eregex.rb, line 25 def self.alphanumeric?(subject, allow_whitespace: false) match(subject, self::PATTERN_ALPHANUMERIC, allow_whitespace: allow_whitespace) end
digits(subject, replace = "")
click to toggle source
# File lib/eregex.rb, line 57 def self.digits(subject, replace = "") self.replace(subject, self::PATTERN_DIGITS, replace) end
digits?(subject, allow_whitespace: false)
click to toggle source
# File lib/eregex.rb, line 29 def self.digits?(subject, allow_whitespace: false) match(subject, self::PATTERN_DIGITS, allow_whitespace: allow_whitespace) end
email?(subject)
click to toggle source
# File lib/eregex.rb, line 33 def self.email?(subject) regex(subject, self::PATTERN_EMAIL) end
match(subject, pattern, allow_whitespace: false)
click to toggle source
# File lib/eregex.rb, line 65 def self.match(subject, pattern, allow_whitespace: false) !!(subject =~ wrap_match_pattern(pattern, allow_whitespace: allow_whitespace)) end
numeric(subject, replace = "")
click to toggle source
# File lib/eregex.rb, line 61 def self.numeric(subject, replace = "") self.replace(subject, self::PATTERN_NUMERIC, replace) end
numeric?(subject)
click to toggle source
# File lib/eregex.rb, line 37 def self.numeric?(subject) match(subject, self::PATTERN_NUMERIC) end
regex(subject, pattern)
click to toggle source
# File lib/eregex.rb, line 69 def self.regex(subject, pattern) !!(subject =~ pattern) end
replace(subject, pattern, replacement = "")
click to toggle source
# File lib/eregex.rb, line 73 def self.replace(subject, pattern, replacement = "") subject.gsub(wrap_replace_pattern(pattern), replacement) end
uuid?(subject)
click to toggle source
# File lib/eregex.rb, line 41 def self.uuid?(subject) regex(subject, self::PATTERN_UUID) end
Protected Class Methods
wrap_match_pattern(pattern, allow_whitespace: false)
click to toggle source
# File lib/eregex.rb, line 84 def wrap_match_pattern(pattern, allow_whitespace: false) /^[#{allow_whitespace ? '\s' : ''}#{pattern}]+$/u end
wrap_replace_pattern(pattern)
click to toggle source
# File lib/eregex.rb, line 80 def wrap_replace_pattern(pattern) /[^#{pattern}]+/u end