Class: CommonRegex
- Inherits:
-
Object
- Object
- CommonRegex
- Defined in:
- lib/commonregex.rb,
lib/commonregex/version.rb
Constant Summary collapse
- VERSION =
'0.1.1'- @@dates_regex =
Regexp.new('(' + CommonRegex.group( CommonRegex.any( [ day_regex + '\\s+(?:of\\s+)?' + month_regex, month_regex + '\\s+' + day_regex ] ) ) + '(?:\\,)?\\s*' + CommonRegex.opt(year_regex) + '|[0-3]?\\d[-/][0-3]?\\d[-/]\\d{2,4})', Regexp::IGNORECASE || Regexp::MULTILINE)
- @@acronyms_regex =
/\b(([A-Z]\.)+|([A-Z]){2,})/m- @@addresses_regex =
/(\d{1,4} [\w\s]{1,20}(?:(street|avenue|road|highway|square|traill|drive|court|parkway|boulevard)\b|(st|ave|rd|hwy|sq|trl|dr|ct|pkwy|blvd)\.(?=\b)?))/im- @@credit_cards_regex =
/((?:(?:\d{4}[- ]){3}\d{4}|\d{16}))(?![\d])/m- @@emails_regex =
/([a-z0-9!#$%&'*+\/=?\^_`{|}~\-]+@([a-z0-9]+\.)+([a-z0-9]+))/im- @@hex_colors_regex =
/(#(?:[0-9a-fA-F]{3}){1,2})\b/im- @@ipv4_regex =
/\b(((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))\b/m- @@ipv6_regex =
/((([0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}:[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){5}:([0-9A-Fa-f]{1,4}:)?[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){4}:([0-9A-Fa-f]{1,4}:){0,2}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){3}:([0-9A-Fa-f]{1,4}:){0,3}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){2}:([0-9A-Fa-f]{1,4}:){0,4}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|(([0-9A-Fa-f]{1,4}:){0,5}:((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|(::([0-9A-Fa-f]{1,4}:){0,5}((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|([0-9A-Fa-f]{1,4}::([0-9A-Fa-f]{1,4}:){0,5}[0-9A-Fa-f]{1,4})|(::([0-9A-Fa-f]@{1,4}:){0,6}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){1,7}:))\b/im- @@links_regex =
/((?:https?:\/\/|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\((?:[^\s()<>]+|(?:\([^\s()<>]+\)))*\))+(?:\((?:[^\s()<>]+|(?:\([^\s()<>]+\)))*@\)|[^\s`!()\[\]{};:\'".,<>?]))/im- @@money_regex =
/(((^|\b)US?)?\$\s?[0-9]{1,3}((,[0-9]{3})+|([0-9]{3})+)?(\.[0-9]{1,2})?\b)/m- @@percentages_regex =
/((100(\.0+)?|[0-9]{1,2}(\.[0-9]+)?)%)/m- @@phones_regex =
/(\d?[^\s\w]*(?:\(?\d{3}\)?\W*)?\d{3}\W*\d{4})/im- @@times_regex =
/\b((0?[0-9]|1[0-2])(:[0-5][0-9])?(am|pm)|([01]?[0-9]|2[0-3]):[0-5][0-9])/im
Class Method Summary collapse
- .any(regexes) ⇒ Object
- .group(regex) ⇒ Object
-
.opt(regex) ⇒ Object
Methods used to generate @date_regex.
Instance Method Summary collapse
-
#initialize(text = '') ⇒ CommonRegex
constructor
A new instance of CommonRegex.
Constructor Details
#initialize(text = '') ⇒ CommonRegex
Returns a new instance of CommonRegex.
56 57 58 |
# File 'lib/commonregex.rb', line 56 def initialize(text = '') @text = text; end |
Class Method Details
.any(regexes) ⇒ Object
12 13 14 |
# File 'lib/commonregex.rb', line 12 def self.any(regexes) regexes.join('|') end |
.group(regex) ⇒ Object
8 9 10 |
# File 'lib/commonregex.rb', line 8 def self.group(regex) '(?:' + regex + ')' end |
.opt(regex) ⇒ Object
Methods used to generate @date_regex
4 5 6 |
# File 'lib/commonregex.rb', line 4 def self.opt(regex) '(?:' + regex + ')?' end |