Module: RegexData

Defined in:
lib/regex_data.rb,
lib/regex_data/version.rb

Constant Summary collapse

VERSION =
"0.1.1"

Class Method Summary collapse

Class Method Details

.ban_word(data, *args) ⇒ Object



36
37
38
39
# File 'lib/regex_data.rb', line 36

def self.ban_word data, *args
  ban = args.join("|")
  return data.gsub(/(#{ban})/, '****')
end

.color_code?(data) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
23
24
25
26
# File 'lib/regex_data.rb', line 20

def self.color_code? data
  if data =~ /rgb\((?:([0-9]{1,2}|1[0-9]{1,2}|2[0-4][0-9]|25[0-5]), ?)(?:([0-9]{1,2}|1[0-9]{1,2}|2[0-4][0-9]|25[0-5]), ?)(?:([0-9]{1,2}|1[0-9]{1,2}|2[0-4][0-9]|25[0-5]))\)/
    return true
  else
    return false
  end
end

.date?(data) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
31
32
33
34
# File 'lib/regex_data.rb', line 28

def self.date? data
  if data =~ /^([0]?[1-9]|[1|2][0-9]|[3][0|1])[\.|\-]([0]?[1-9]|[1][0-2])[\.|\-]([0-9]{4}|[0-9]{2})$/
    return true
  else
    return false
  end
end

.email?(data) ⇒ Boolean

Returns:

  • (Boolean)


4
5
6
7
8
9
10
# File 'lib/regex_data.rb', line 4

def self.email? data
  if data =~ /^(?:(?:[\w`~!#$%^&*\-=+;:{}'|,?\/]+(?:(?:\.(?:"(?:\\?[\w`~!#$%^&*\-=+;:{}'|,?\/\.()<>\[\] @]|\\"|\\\\)*"|[\w`~!#$%^&*\-=+;:{}'|,?\/]+))*\.[\w`~!#$%^&*\-=+;:{}'|,?\/]+)?)|(?:"(?:\\?[\w`~!#$%^&*\-=+;:{}'|,?\/\.()<>\[\] @]|\\"|\\\\)+"))@(?:[a-zA-Z\d\-]+(?:\.[a-zA-Z\d\-]+)*|\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\])$/
    return true
  else
    return false
  end
end

.ip_address_v4?(data) ⇒ Boolean

Returns:

  • (Boolean)


66
67
68
69
70
71
72
# File 'lib/regex_data.rb', line 66

def self.ip_address_v4? data
  if data =~ /\b(?:(?:2(?:[0-4][0-9]|5[0-5])|[0-1]?[0-9]?[0-9])\.){3}(?:(?:2([0-4][0-9]|5[0-5])|[0-1]?[0-9]?[0-9]))\b/
    return true
  else
    return false
  end
end

.max_length(data, max) ⇒ Object



54
55
56
# File 'lib/regex_data.rb', line 54

def self.max_length data, max
  data.length <= max ? true : false
end

.min_length(data, min) ⇒ Object



50
51
52
# File 'lib/regex_data.rb', line 50

def self.min_length data, min
  data.length >= min ? true : false
end

.remove_all_spaces(data) ⇒ Object



46
47
48
# File 'lib/regex_data.rb', line 46

def self.remove_all_spaces data
  return  data.gsub(/\s+/, '')
end

.remove_empty_lineObject



58
59
60
# File 'lib/regex_data.rb', line 58

def self.remove_empty_line
  return data.gsub(/[\n]+/, "\n")
end

.remove_extra_space(data) ⇒ Object



41
42
43
44
# File 'lib/regex_data.rb', line 41

def self.remove_extra_space data
  data.gsub!(/\s+/, ' ')
  return data.gsub(/^\s+|\s+$/, '')
end

.remove_html_tag(data) ⇒ Object



62
63
64
# File 'lib/regex_data.rb', line 62

def self.remove_html_tag data
  return data.gsub(/(<(\/?[^\>]+)>)/, "")
end

.strong_password?(data) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
15
16
17
18
# File 'lib/regex_data.rb', line 12

def self.strong_password? data
  if data =~ /^(?!.*(.)\1{1})(?=(.*[\d]){2,})(?=(.*[a-z]){2,})(?=(.*[A-Z]){2,})(?=(.*[@#$%!]){2,})(?:[\da-zA-Z@#$%!]){15,100}$/
    return true
  else
    return false
  end
end

.url?(data) ⇒ Boolean

Returns:

  • (Boolean)


74
75
76
77
78
79
80
# File 'lib/regex_data.rb', line 74

def self.url? data
  if data =~ /((?:https\:\/\/)|(?:http\:\/\/)|(?:www\.))?([a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(?:\??)[a-zA-Z0-9\-\._\?\,\'\/\\\+&%\$#\=~]+)/
    return true
  else
    return false
  end
end