Created
April 14, 2015 17:11
-
-
Save crueber/d2c9135d7059f136dfe9 to your computer and use it in GitHub Desktop.
Useful Regexps in CoffeeScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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