Module: Regex::Templates

Included in:
Regex
Defined in:
lib/regex/templates.rb

Overview

Templates

TODO: What about regular expressions with variable content? But then how would we handle named substituions?

TODO: Should these be methods rather than constants?

Constant Summary collapse

EMPTY =

Empty line.

/^$/
BLANK =

Blank line.

/^\s*$/
NUMBER =
/[-+]?[0-9]*\.?[0-9]+/
MLTAG =

Markup language tag, e.g <a>stuff</a>.

/<([A-Z][A-Z0-9]*)\b[^>]*>(.*?)<\/\1>/i
IPV4 =

IPv4 Address

/\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b/
DNI =

Dni (spanish ID card)

/^\d{8}[A-Za-z]{1}$/
EMAIL =

Email Address

/([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)/i
USPHONE =

United States phone number.

/(\d\d\d[-]|\(\d\d\d\))?(\d\d\d)[-](\d\d\d\d)/
USZIP =

United States zip code.

/^[0-9]{5}(-[0-9]{4})?$/
SSN =

United States social secuirty number.

/[0-9]\{3\}-[0-9]\{2\}-[0-9]\{4\}/
DOLLARS =

United States dollar amount.

/\$[0-9]*.[0-9][0-9]/
BIC =

Bank Ientification Code

/([a-zA-Z]{4}[a-zA-Z]{2}[a-zA-Z0-9]{2}([a-zA-Z0-9]{3})?)/
IBAN =
/[a-zA-Z]{2}[0-9]{2}[a-zA-Z0-9]{4}[0-9]{7}([a-zA-Z0-9]?){0,16}/
HEX =

Hexidecimal value.

/(#([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})\b)/
HTTP =

HTTP URL Address

/^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \?=.-]*)*\/?$/
CREDITCARD =

Validates Credit Card numbers, contains 16 numbers in groups of 4 separated by ‘-`, space or nothing.

/^(\d{4}-){3}\d{4}$|^(\d{4}\s){3}\d{4}$|^\d{16}$/
MASTERCARD =

MasterCard credit card

/^5[1-5]\d{14}$/
VISA =

Visa credit card.

/^4\d{15}$/
UNIXWORD =

TODO: Better name?

/^[a-zA-Z0-9_]*$/
USERNAME =

Username, at lest 3 characters and no more than 16.

/^[a-zA-Z0-9_]{3,16}$/
TWITTER_USERNMAE =

Twitter username

/^([a-z0-9\_])+$/ix
GITHUB_USERNAME =

Github username

/^([a-z0-9\_\-])+$/ix
SLIDESHARE_USERNAME =

Slideshare username

/^([a-z0-9])+$/ix
DELICIOUS_USERNMAME =

Del.icio.us username

/^([a-z0-9\_\-])+$/ix
RUBYBLOCK =

Ruby comment block.

/^=begin\s*(.*?)\n(.*?)\n=end/m
RUBYMETHOD_WITH_COMMENT =

Ruby method definition. TODO: Not quite right.

/(^\ *\#.*?)^\s*def\s*(.*?)$/m
RUBYMETHOD =

Ruby method definition.

/^\ *def\s*(.*?)$/
PRIMEONES =

By the legendary abigail. Fails to match if and only if it is matched against a prime number of 1’s. That is, ‘11’ fails, but ‘1111’ does not. I once heard him talk why this works, but I forgot most of it.

/^1?$|^(11+?)\1+$/

Class Method Summary collapse

Class Method Details

.[](name) ⇒ Object

Lookup a template by name.



105
106
107
# File 'lib/regex/templates.rb', line 105

def self.[](name)
  Templates.const_get(name.upcase)
end

.listObject

Name of all constants.



100
101
102
# File 'lib/regex/templates.rb', line 100

def self.list
  constants.map{ |c| c.downcase }
end