Skip to content

Instantly share code, notes, and snippets.

@singlewind
Created July 4, 2013 00:37
Show Gist options
  • Save singlewind/5924042 to your computer and use it in GitHub Desktop.
Save singlewind/5924042 to your computer and use it in GitHub Desktop.
Common Regex
http://net.tutsplus.com/tutorials/other/8-regular-expressions-you-should-know/
1. Matching a Username
/^[a-z0-9_-]{3,16}$/
2. Matching a Password
/^[a-z0-9_-]{6,18}$/
3. Matching a Hex Value
/^#?([a-f0-9]{6}|[a-f0-9]{3})$/
4. Matching a Slug
/^[a-z0-9-]+$/
5. Matching an Email
/^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/
6. Matching a URL
/^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/
7. Matching an 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]?)$/
8. Matching an HTML Tag
/^<([a-z]+)([^<]+)*(?:>(.*)<\/\1>|\s+\/>)$/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment