表達式: ^\d{3}-\d{2}-\d{4}$
描述:此正則表達式將會匹配設備號碼(美國)(SSN) ,格式爲NNN-NN-NNNN.
匹配舉例:333-22-4444 | 123-45-6789
不匹配舉例: 123456789 | SSN
表達式: ^[a-zA-Z]$
描述: 匹配任何單一的大寫或小寫字母。
匹配舉例: a | B | c
不匹配舉例: 0 | & | AbC
表達式:(\w+)\s+\1
描述: 此表達式使用反向引用來尋找以空格分開的兩個單詞中出現一行中出現兩次的單詞。匹配像 'mandate dated'這樣的。
匹配舉例:hubba hubba | mandate dated | an annual
不匹配舉例: may day | gogo | 1212
表達式: ^(\d{4}[- ]){3}\d{4}|\d{16}$
描述:信用卡卡號校驗。檢查16位四組格式的,以空個或-分開的卡號,或者連在一塊兒的。.
匹配舉例:1234-1234-1234-1234 | 1234 1234 1234 1234 | 1234123412341234
不匹配舉例: Visa | 1234 | 123-1234-12345
表達式:^((4\d{3})|(5[1-5]\d{2})|(6011))-?\d{4}-?\d{4}-?\d{4}|3[4,7]\d{13}$
描述:匹配主要的信用卡如: Visa (長16, 以 4開頭), Mastercard (長 16, 以 51-55), Discover (長 16, 以 6011開頭), American Express (長 15, 以 34 或 37開頭). 全部的以 16 位數字格式,能夠有或沒有(-)在四個一組的數字中間。
匹配:6011-1111-1111-1111 | 5423-1111-1111-1111 | 341111111111111
不匹配: 4111-111-111-111 | 3411-1111-1111-111 | Visa
表達式: ^\s*[a-zA-Z,\s]+\s*$
描述:任何大寫或小寫字母組成,以逗號或空格分開的文本,空格的數量不限。
匹配:Smith, Ed | Ed Smith | aBcDeFgH
不匹配: a123 | AB5 | Mr. Ed
表達式: ^\d{9}[\d|X]$
描述:一個簡單的ISBN 校驗表達式 –它僅僅校驗10位數字構成的,最後一位或許爲X的ISBN號。
匹配:1234123412 | 123412341X
不匹配:不是一個isbn
表達式:(?:4\d{3})|(?:5[1-5]\d{2})|(?:6011)|(?:3[68]\d{2})|(?:30[012345]\d))[ -]?(\d{4})[ -]?(\d{4})[ -]?(\d{4}|3[4,7]\d{13})$
描述:信用卡卡號校驗。
匹配:6011567812345678 | 6011 5678 1234 5678 | 6011-5678-1234-5678
不匹配: 1234567890123456
表達式: "((\\")|[^"(\\")])+"
描述:匹配以引號引發的字符串,使用斜槓的字符串。
匹配「 "test" | "escape\"quote" | "\""
不匹配: test | "test | "test\"
表達式: ^([1-zA-Z0-1@.\s]{1,255})$
描述:通用字符串校驗表達式,能夠防止用戶輸入惡意字符代碼,容許輸入email地址,姓名,地址,密碼等等。不容許輸入斜槓 *等非法字符。
匹配:email@email.com | My Name | asdf12df
不匹配: ‘,\*&$<> | 1001' string
表達式:^([A-Z]{1}[a-z]{1,})$|^([A-Z]{1}[a-z]{1,}\040[A-Z]{1}[a-z]{1,})$|^([A-Z]{1}[a-z]{1,}\040[A-Z]{1}[a-z]{1,}\040[A-Z]{1}[a-z]{1,})$|^$
描述:匹配首字母大寫的以空格分開的字符串,也匹配空字符串。
匹配: Sacramento | San Francisco | San Luis Obispo
不匹配: SanFrancisco | SanLuisObispo | San francisco
表達式:(^|\s)(00[1-9]|0[1-9]0|0[1-9][1-9]|[1-6]\d{2}|7[0-6]\d|77[0-2])(-?|[\. ])([1-9]0|0[1-9]|[1-9][1-9])\3(\d{3}[1-9]|[1-9]\d{3}|\d[1-9]\d{2}|\d{2}[1-9]\d)($|\s|[;:,!\.\?])
描述: Incorporated other people's examples; removed extraneous parenthesis on 10/7/04. Currently the SSA site says 772 is the highest AREA number generated (http://www.ssa.gov/employer/highgroup.txt). Old expression was: (^|\s)\d{3}(-?|[\. ])\d{2}\2\d{4}($|\s|[;:,!\.\?]). Looks for either the beginning of a line or whitespace before the beginning of the social security number, then either zero or one hyphen OR one of a period or space, then uses the \3 to reference the value returned in the parenthesis that includes the -?|[\. ] (basically says if the first dash, period, or space is there, then the second one is required; and if the first dash, period, or space is not there, then the second one can't be either), and finally looks for the end of a line, whitespace, or punctuation characters after the social security number.
匹配:123-45-6789 | 123 45 6789 | 123456789
不匹配: 12345-67-890123 | 1234-56-7890 | 123-45-78901
表達式:<[^>]+>
描述:這個表達式用來查找全部的開閉標記,可很好的用於HTML或XML文檔的標記清理。我用來清理HTML中的XML標記。我找出全部的標記,而後刪除那些非標準的的標記。
匹配: <html> | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> | <
不匹配: Any plain old text | http://www.regexlib.com/Add.aspx | xml>
表達式:^[0-9]{1,}(,[0-9]+){0,}$
描述:它能夠校驗html頁面的格式輸入(checkbox, optionbox, selectbox)等,尤爲是一次輸入多個數字值的時候,例如用戶一次選擇一個或更多的時候!
匹配: 1111 | 47,26,2,1,1111,12 | 25,1245,2122,23232
不匹配: 111, | 1a1,111,1212,23 | 11aa,aaa,asas,asa
表達式:^(?!^(PRN|AUX|CLOCK\$|NUL|CON|COM\d|LPT\d|\..*)(\..+)?$)[^\x00-\x1f\\?*<>:\;|\"/]+$
描述:對保留字符進行檢查,如 <> 和 "。
匹配:abc
不匹配: PRN
表達式:^([a-z0-9]+([\-a-z0-9]*[a-z0-9]+)?\.){0,}([a-z0-9]+([\-a-z0-9]*[a-z0-9]+)?){1,63}(\.[a-z0-9]{2,7})+$
描述: [註釋:這個域名經過 Macromedia's ColdFusion MX測試.我確定它工做於其餘正則引擎時還須要額外的信息。]在找了一些正則表達式後,我發現沒有一個能夠徹底的可靠的處理子域名或者頂級域名的正則表達式。所以,我寫了一個,而後測試它。它不匹配如: -.domain.com, -a.domain.com, -domain.com, domain-.com, 以及在頂級域名前的字符數超過63個的域名。匹配: a.domain.com, a-a.domain.com, a--a.domain.com, a--defg.com, domain.co.uk.
匹配: 800-med-alert.com | jump.to | archive-3.www.regexlib.com
不匹配: example | a-.domain.com | http://regexlib.com/
表達式:^(?![0-9]{6})[0-9a-zA-Z]{6}$
描述:匹配一個六位的密碼,而且其中至少含有一個字母。
匹配:123a12 | a12345 | aaaaaa
不匹配: 111111