Skip to content

Instantly share code, notes, and snippets.

@delameko
Last active September 27, 2015 15:28
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 delameko/1291391 to your computer and use it in GitHub Desktop.
Save delameko/1291391 to your computer and use it in GitHub Desktop.
Useful regular expressions for Ruby
# Useful regular expressions
# http://net.tutsplus.com/tutorials/other/8-regular-expressions-you-should-know/
# username
/^[a-z0-9_-]{3,16}$/
# password
/^[a-z0-9_-]{6,18}$/
# Hex value
/^#?([a-f0-9]{6}|[a-f0-9]{3})$/
# Slug
/^[a-z0-9-]+$/
# Email
/^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/
# URL
/^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/
# IP Address
/^(?:(?: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]?)$/
# HTML Tag
/^<([a-z]+)([^<]+)*(?:>(.*)<\/\1>|\s+\/>)$/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment