Regular Expressions List


/ Published in: Regular Expression
Save to your folder(s)

List of useful Regular Expressions


Copy this code and paste it in your HTML
  1. //Regular Expressions List
  2.  
  3. //Short Tutorial
  4.  
  5. \ // the escape character - used to find an instance of a metacharacter like a period, brackets, etc.
  6. . // match any character except newline
  7. x // match any instance of x
  8. ^x // match any character except x
  9. [x] // match any instance of x in the bracketed range - [abxyz] will match any instance of a, b, x, y, or z
  10. | // an OR operator - [x|y] will match an instance of x or y
  11. () // used to group sequences of characters or matches
  12. {} // used to define numeric quantifiers
  13. {x} // match must occur exactly x times
  14. {x,} // match must occur at least x times
  15. {x,y} // match must occur at least x times, but no more than y times
  16. ? // preceding match is optional or one only, same as {0,1}
  17. * // find 0 or more of preceding match, same as {0,}
  18. + // find 1 or more of preceding match, same as {1,}
  19. ^ // match the beginning of the line
  20. $ // match the end of a line
  21.  
  22. [:alpha:] // Represents an alphabetic character. Use [:alpha:]+ to find one of them.
  23. [:digit:] // Represents a decimal digit. Use [:digit:]+ to find one of them.
  24. [:alnum:] // Represents an alphanumeric character ([:alpha:] and [:digit:]).
  25. [:space:] // Represents a space character (but not other whitespace characters).
  26. [:print:] // Represents a printable character.
  27. [:cntrl:] // Represents a nonprinting character.
  28. [:lower:] // Represents a lowercase character if Match case is selected in Options.
  29. [:upper:] // Represents an uppercase character if Match case is selected in Options.
  30.  
  31. \d // matches a digit, same as [0-9]
  32. \D // matches a non-digit, same as [^0-9]
  33. \s // matches a whitespace character (space, tab, newline, etc.)
  34. \S // matches a non-whitespace character
  35. \w // matches a word character
  36. \W // matches a non-word character
  37. \b // matches a word-boundary (NOTE: within a class, matches a backspace)
  38. \B // matches a non-wordboundary
  39.  
  40. // http://regexlib.com
  41. // http://net.tutsplus.com/tutorials/other/8-regular-expressions-you-should-know/
  42.  
  43. // Email address
  44.  
  45. ^[\\w\\-]+(\\.[\\w\\-]+)*@([A-Za-z0-9-]+\\.)+[A-Za-z]{2,4}$
  46. ^[\w-]+(\.[\w-]+)*@([a-z0-9-]+(\.[a-z0-9-]+)*?\.[a-z]{2,6}|(\d{1,3}\.){3}\d{1,3})(:\d{4})?$
  47. ^([\w\.*\-*]+@([\w]\.*\-*)+[a-zA-Z]{2,9}(\s*;\s*[\w\.*\-*]+@([\w]\.*\-*)+[a-zA-Z]{2,9})*)$ //List of semi-colon seperated email addresses
  48. ^([a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4})*$
  49.  
  50. // IP Address
  51.  
  52. ^((?:(?: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]?))*$
  53.  
  54. // Credit Cards
  55.  
  56. ^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6011[0-9]{12}|622((12[6-9]|1[3-9][0-9])|([2-8][0-9][0-9])|(9(([0-1][0-9])|(2[0-5]))))[0-9]{10}|64[4-9][0-9]{13}|65[0-9]{14}|3(?:0[0-5]|[68][0-9])[0-9]{11}|3[47][0-9]{13})*$
  57.  
  58. // Username of type test@test
  59.  
  60. [^@/]+@[^@/]+
  61.  
  62. // Multiple spaces replacement
  63.  
  64. \\s+
  65.  
  66. // Non-alphanumeric replacement
  67.  
  68. [^a-zA-Z0-9]
  69.  
  70. // Blank line
  71.  
  72. ^$
  73.  
  74. // Positive integers
  75.  
  76. ^[1-9]+[0-9]*$
  77.  
  78. // Positive decimal values
  79.  
  80. (^\d*\.?\d*[0-9]+\d*$)|(^[0-9]+\d*\.\d*$)
  81.  
  82. // Percentage (2 decimal places)
  83.  
  84. ^-?[0-9]{0,2}(\.[0-9]{1,2})?$|^-?(100)(\.[0]{1,2})?$
  85.  
  86. // State abbreviation
  87.  
  88. [A-Z][A-Z] //you may choose to put spaces either before or after the regex.
  89.  
  90. // Phone Numbers
  91.  
  92. (^\+[0-9]{2}|^\+[0-9]{2}\(0\)|^\(\+[0-9]{2}\)\(0\)|^00[0-9]{2}|^0)([0-9]{9}$|[0-9\-\s]{10}$)
  93.  
  94. // City, State abbreviation
  95.  
  96. .*, [A-Z][A-Z]
  97.  
  98. // Zip Code
  99.  
  100. [0-9]\{5\}(-[0-9]\{4\})? //84094 or 84094-1234
  101.  
  102. // Social security number, such as: ###-##-####
  103.  
  104. [0-9]\{3\}-[0-9]\{2\}-[0-9]\{4\}
  105.  
  106. // Dollar amounts, specified with a leading $ symbol
  107.  
  108. \$[0-9]*.[0-9][0-9]
  109.  
  110. // DATE
  111.  
  112. [0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\} //2003-08-06
  113. [A-Z][a-z][a-z] [0-9][0-9]*, [0-9]\{4\} //Jan 3, 2003
  114. ^(\d{1,2})\/(\d{1,2})\/(\d{2}|(19|20)\d{2})$ //DD/MM/YY or DD/MM/YYYY or MM/DD/YY or MM/DD/YYYY
  115.  
  116. // HTML Tags except <p> </p>
  117.  
  118. <(?>/?)(?!p).+?>
  119.  
  120. // Font Tags Replacement
  121.  
  122. <(FONT|font)([ ]([a-zA-Z]+)=("|')[^"\']+("|'))*[^>]+>([^<]+)(</FONT>|</font>
  123.  
  124. // URL
  125. ^http(s)?:\/\/((\d+\.\d+\.\d+\.\d+)|(([\w-]+\.)+([a-z,A-Z][\w-]*)))(:[1-9][0-9]*)?(\/([\w-.\/:%+@&=]+[\w- .\/?:%+@&=]*)?)?(#(.*))?$/i
  126.  
  127. // NOTEPAD ++ Replace
  128. // Insert a span in anchor
  129. Find : (<a.*>)(.*)</a>
  130. Replace : \1<span class="icon3 pdf">\2</span></a>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.