Created
June 4, 2012 13:00
-
-
Save Dynyx/2868221 to your computer and use it in GitHub Desktop.
Handy regex expressions
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
//replace all but links | |
/<(?!\/?a(?=>|\s.*>))\/?.*?>/g | |
//validate url | |
/^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \?=.-]*)*\/?$/ | |
//Validate US phone number | |
/^(\+\d)*\s*(\(\d{3}\)\s*)*\d{3}(-{0,1}|\s{0,1})\d{2}(-{0,1}|\s{0,1})\d{2}$/ | |
//Test if a password is strong | |
(?=^.{8,}$)((?=.*\d)|(?=.*\W+))(?![.\n])(?=.*[A-Z])(?=.*[a-z]).*$ | |
//Validate US zip code | |
^[0-9]{5}(-[0-9]{4})?$ | |
//Validate Canadian postal code | |
^[ABCEGHJ-NPRSTVXY]{1}[0-9]{1}[ABCEGHJ-NPRSTV-Z]{1}[ ]?[0-9]{1}[ABCEGHJ-NPRSTV-Z]{1}[0-9]{1}$ | |
//Grab unclosed img tags | |
<img([^>]+)(\s*[^\/])> | |
//Find all CSS attributes | |
\s(?[a-zA-Z-]+)\s[:]{1}\s*(?[a-zA-Z0-9\s.#]+)[;]{1} | |
//Get code within <?php and ?> | |
<\?[php]*([^\?>]*)\?> | |
//Validate Canadian postal code | |
/^\s*[a-ceghj-npr-tvxy]\d[a-ceghj-npr-tv-z](\s)?\d[a-ceghj-npr-tv-z]\d\s*$/i |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment