Skip to content

Instantly share code, notes, and snippets.

@crueber
Created April 14, 2015 17:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crueber/d2c9135d7059f136dfe9 to your computer and use it in GitHub Desktop.
Save crueber/d2c9135d7059f136dfe9 to your computer and use it in GitHub Desktop.
Useful Regexps in CoffeeScript
PRE_AND_POST_UNDERSCORES = /^_+|_+$/g
EMAIL = /^[a-z0-9!#$%&'*+\/=?^_`{|}~.-]+@[a-z0-9]([a-z0-9-]*[a-z0-9])?(\.[a-z0-9]([a-z0-9-]*[a-z0-9])?)*$/i
URL = /^(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?$/
# HTML Based
SINGLE_TAG = /^<(\w+)\s*\/?>(?:<\/\1>|)$/
HTML = /<|&#?\w+;/
TAG_NAME = /<([\w:]+)/;
XHTML_TAG = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/gi;
# Date Based
ISO_DATE = /\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z)/
SIMPLIFIED_DATE = /^(\d{4})-(\d{2})-(\d{2})$/
TIME = /^(\d\d):(\d\d)(?::(\d\d)(\.\d{1,3})?)?$/
# Number Based
NUMBER = /^\s*(\-|\+)?(\d+|(\d*(\.\d*)))\s*$/
# Useful Functions
trim_underscores = -> (str) -> str.replace(PRE_AND_POST_UNDERSCORES, '')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment