1. 平时做网站经常要用正则表达式,下面是一些讲解和例子,仅供大家参考和修改使用:
2. "^d+$" //非负整数(正整数 + 0)
3. "^[0-9]*[1-9][0-9]*$" //正整数
4. "^((-d+)|(0+))$" //非正整数(负整数 + 0)
5. "^-[0-9]*[1-9][0-9]*$" //负整数
6. "^-?d+$" //整数
7. "^d+(.d+)?$" //非负浮点数(正浮点数 + 0)
8. "^(([0-9]+.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*.[0-9]+)|([0-9]*[1-9][0-9]*))$" //正浮点数
9. "^((-d+(.d+)?)|(0+(.0+)?))$" //非正浮点数(负浮点数 + 0)
10. "^(-(([0-9]+.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*.[0-9]+)|([0-9]*[1-9][0-9]*)))$" //负浮点数
11. "^(-?d+)(.d+)?$" //浮点数
12. "^[A-Za-z]+$" //由26个英文字母组成的字符串
13. "^[A-Z]+$" //由26个英文字母的大写组成的字符串
14. "^[a-z]+$" //由26个英文字母的小写组成的字符串
15. "^[A-Za-z0-9]+$" //由数字和26个英文字母组成的字符串
16. "^w+$" //由数字、26个英文字母或者下划线组成的字符串
17. "^[w-]+(.[w-]+)*@[w-]+(.[w-]+)+$" //email地址
18. "^[a-zA-z]+://(w+(-w+)*)(.(w+(-w+)*))*(?S*)?$" //url
19. /^(d{2}|d{4})-((0([1-9]{1}))|(1[1|2]))-(([0-2]([1-9]{1}))|(3[0|1]))$/ // 年-月-日
20. /^((0([1-9]{1}))|(1[1|2]))/(([0-2]([1-9]{1}))|(3[0|1]))/(d{2}|d{4})$/ // 月/日/年
21. "^([w-.]+)@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.)|(([w-]+.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(]?)$" //Emil
22. /^((+?[0-9]{2,4}-[0-9]{3,4}-)|([0-9]{3,4}-))?([0-9]{7,8})(-[0-9]+)?$/ //电话号码
23. "^(d{1,2}|1dd|2[0-4]d|25[0-5]).(d{1,2}|1dd|2[0-4]d|25[0-5]).(d{1,2}|1dd|2[0-4]d|25[0-5]).(d{1,2}|1dd|2[0-4]d|25[0-5])$" //IP地址
24.
25. 匹配中文字符的正则表达式: [u4e00-u9fa5]
26. 匹配双字节字符(包括汉字在内):[^x00-xff]
27. 匹配空行的正则表达式:[s| ]*
28. 匹配HTML标记的正则表达式:/<(.*)>.*</1>|<(.*) />/
29. 匹配首尾空格的正则表达式:(^s*)|(s*$)
30. 匹配Email地址的正则表达式:w+([-+.]w+)*@w+([-.]w+)*.w+([-.]w+)*
31. 匹配网址URL的正则表达式:^[a-zA-z]+://(w+(-w+)*)(.(w+(-w+)*))*(?S*)?$
32. 匹配帐号是否合法(字母开头,允许5-16字节,允许字母数字下划线):^[a-zA-Z][a-zA-Z0-9_]{4,15}$
33. 匹配国内电话号码:(d{3}-|d{4}-)?(d{8}|d{7})?
34. 匹配腾讯QQ号:^[1-9]*[1-9][0-9]*$
35.
36.
37. 元字符及其在正则表达式上下文中的行为:
38.
39. 将下一个字符标记为一个特殊字符、或一个原义字符、或一个后向引用、或一个八进制转义符。
40.
41. ^ 匹配输入字符串的开始位置。如果设置了 RegExp 对象的Multiline 属性,^ 也匹配 ’’ 或 ’’ 之后的位置。
42.
43. $ 匹配输入字符串的结束位置。如果设置了 RegExp 对象的Multiline 属性,$ 也匹配 ’’ 或 ’’ 之前的位置。
44.
45. * 匹配前面的子表达式零次或多次。
46.
47. + 匹配前面的子表达式一次或多次。+ 等价于 {1,}。
48.
49. ? 匹配前面的子表达式零次或一次。? 等价于 {0,1}。
50.
51. {n} n 是一个非负整数,匹配确定的n 次。
52.
53. {n,} n 是一个非负整数,至少匹配n 次。
54.
55. {n,m} m 和 n 均为非负整数,其中n <= m。最少匹配 n 次且最多匹配 m 次。在逗号和两个数之间不能有空格。
56.
57. ? 当该字符紧跟在任何一个其他限制符 (*, +, ?, {n}, {n,}, {n,m}) 后面时,匹配模式是非贪婪的。非贪婪模式尽可能少的匹配所搜索的字符串,而默认的贪婪模式则尽可能多的匹配所搜索的字符串。
58.
59. . 匹配除 "" 之外的任何单个字符。要匹配包括 ’’ 在内的任何字符,请使用象 ’[.]’ 的模式。
60. (pattern) 匹配pattern 并获取这一匹配。
61.
62. (?:pattern) 匹配pattern 但不获取匹配结果,也就是说这是一个非获取匹配,不进行存储供以后使用。
63.
64. (?=pattern) 正向预查,在任何匹配 pattern 的字符串开始处匹配查找字符串。这是一个非获取匹配,也就是说,该匹配不需要获取供以后使用。
65.
66. (?!pattern) 负向预查,与(?=pattern)作用相反
67.
68. x|y 匹配 x 或 y。
69.
70. [xyz] 字符集合。
71.
72. [^xyz] 负值字符集合。
73.
74. [a-z] 字符范围,匹配指定范围内的任意字符。
75.
76. [^a-z] 负值字符范围,匹配任何不在指定范围内的任意字符。
77.
78. 匹配一个单词边界,也就是指单词和空格间的位置。
79.
80. B 匹配非单词边界。
81.
82. cx 匹配由x指明的控制字符。
83.
84. d 匹配一个数字字符。等价于 [0-9]。
85.
86. D 匹配一个非数字字符。等价于 [^0-9]。
87.
88. f 匹配一个换页符。等价于 x0c 和 cL。
89.
90. 匹配一个换行符。等价于 x0a 和 cJ。
91.
92. 匹配一个回车符。等价于 x0d 和 cM。
93.
94. s 匹配任何空白字符,包括空格、制表符、换页符等等。等价于[ f v]。
95.
96. S 匹配任何非空白字符。等价于 [^ f v]。
97.
98. 匹配一个制表符。等价于 x09 和 cI。
99.
100. v 匹配一个垂直制表符。等价于 x0b 和 cK。
101.
102. w 匹配包括下划线的任何单词字符。等价于’[A-Za-z0-9_]’。
103.
104. W 匹配任何非单词字符。等价于 ’[^A-Za-z0-9_]’。
105.
106. xn 匹配 n,其中 n 为十六进制转义值。十六进制转义值必须为确定的两个数字长。
107.
108. um 匹配 num,其中num是一个正整数。对所获取的匹配的引用。
109.
110. 标识一个八进制转义值或一个后向引用。如果 之前至少 n 个获取的子表达式,则 n 为后向引用。否则,如果 n 为八进制数字 (0-7),则 n 为一个八进制转义值。
111.
112. m 标识一个八进制转义值或一个后向引用。如果 m 之前至少有is preceded by at least nm 个获取得子表达式,则 nm 为后向引用。如果 m 之前至少有 n 个获取,则 n 为一个后跟文字 m 的后向引用。如果前面的条件都不满足,若 n 和 m 均为八进制数字 (0-7),则 m 将匹配八进制转义值 nm。
113.
114. ml 如果 n 为八进制数字 (0-3),且 m 和 l 均为八进制数字 (0-7),则匹配八进制转义值 nml。
115.
116. un 匹配 n,其中 n 是一个用四个十六进制数字表示的Unicode字符。
117.
118. 匹配中文字符的正则表达式: [u4e00-u9fa5]
119.
120. 匹配双字节字符(包括汉字在内):[^x00-xff]
121.
122. 匹配空行的正则表达式:n[s| ]*r
123.
124. 匹配HTML标记的正则表达式:/<(.*)>.*|<(.*) />/
125.
126. 匹配首尾空格的正则表达式:(^s*)|(s*$)
127.
128. 匹配Email地址的正则表达式:w+([-+.]w+)*@w+([-.]w+)*.w+([-.]w+)*
129.
130. 匹配网址URL的正则表达式:http://([w-]+.)+[w-]+(/[w- ./?%&=]*)?
131.
132. 利用正则表达式限制网页表单里的文本框输入内容:
133.
134. 用正则表达式限制只能输入中文:onkeyup="value=value.replace(/[^u4E00-u9FA5]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^u4E00-u9FA5]/g,''))"
135.
136. 用正则表达式限制只能输入全角字符: onkeyup="value=value.replace(/[^uFF00-uFFFF]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^uFF00-uFFFF]/g,''))"
137.
138. 用正则表达式限制只能输入数字:onkeyup="value=value.replace(/[^d]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^d]/g,''))"
139.
140. 用正则表达式限制只能输入数字和英文:onkeyup="value=value.replace(/[W]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^d]/g,''))"
141.
142. =========常用正则式
143.
144.
145.
146. 匹配中文字符的正则表达式: [u4e00-u9fa5]
147.
148. 匹配双字节字符(包括汉字在内):[^x00-xff]
149.
150. 匹配空行的正则表达式:[s| ]*
151.
152. 匹配HTML标记的正则表达式:/<(.*)>.*</1>|<(.*) />/
153.
154. 匹配首尾空格的正则表达式:(^s*)|(s*$)
155.
156. 匹配IP地址的正则表达式:/(d+).(d+).(d+).(d+)/g //
157.
158. 匹配Email地址的正则表达式:w+([-+.]w+)*@w+([-.]w+)*.w+([-.]w+)*
159.
160. 匹配网址URL的正则表达式:http://(/[w-]+.)+[w-]+(/[w- ./?%&=]*)?
161.
162. sql语句:^(select|drop|delete|create|update|insert).*$
163.
164. 1、非负整数:^d+$
165.
166. 2、正整数:^[0-9]*[1-9][0-9]*$
167.
168. 3、非正整数:^((-d+)|(0+))$
169.
170. 4、负整数:^-[0-9]*[1-9][0-9]*$
171.
172. 5、整数:^-?d+$
173.
174. 6、非负浮点数:^d+(.d+)?$
175.
176. 7、正浮点数:^((0-9)+.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*.[0-9]+)|([0-9]*[1-9][0-9]*))$
177.
178. 8、非正浮点数:^((-d+.d+)?)|(0+(.0+)?))$
179.
180. 9、负浮点数:^(-((正浮点数正则式)))$
181.
182. 10、英文字符串:^[A-Za-z]+$
183.
184. 11、英文大写串:^[A-Z]+$
185.
186. 12、英文小写串:^[a-z]+$
187.
188. 13、英文字符数字串:^[A-Za-z0-9]+$
189.
190. 14、英数字加下划线串:^w+$
191.
192. 15、E-mail地址:^[w-]+(.[w-]+)*@[w-]+(.[w-]+)+$
193.
194. 16、URL:^[a-zA-Z]+://(w+(-w+)*)(.(w+(-w+)*))*(?s*)?$
195. 或:^http://[A-Za-z0-9]+.[A-Za-z0-9]+[/=?%-&_~`@[]':+!]*([^<>""])*$
196.
197. 17、邮政编码:^[1-9]d{5}$
198.
199. 18、中文:^[u0391-uFFE5]+$
200.
201. 19、电话号码:^(((d{2,3}))|(d{3}-))?((0d{2,3})|0d{2,3}-)?[1-9]d{6,7}(-d{1,4})?$
202.
203. 20、手机号码:^(((d{2,3}))|(d{3}-))?13d{9}$
204.
205. 21、双字节字符(包括汉字在内):^x00-xff
206.
207. 22、匹配首尾空格:(^s*)|(s*$)(像vbscript那样的trim函数)
208.
209. 23、匹配HTML标记:<(.*)>.*</1>|<(.*) />
210.
211. 24、匹配空行:[s| ]*
212.
213. 25、提取信息中的网络链接:(h|H)(r|R)(e|E)(f|F) *= *('|")?(w||/|.)+('|"| *|>)?
214.
215. 26、提取信息中的邮件地址:w+([-+.]w+)*@w+([-.]w+)*.w+([-.]w+)*
216.
217. 27、提取信息中的图片链接:(s|S)(r|R)(c|C) *= *('|")?(w||/|.)+('|"| *|>)?
218.
219. 28、提取信息中的IP地址:(d+).(d+).(d+).(d+)
220.
221. 29、提取信息中的中国手机号码:(86)*0*13d{9}
222.
223. 30、提取信息中的中国固定电话号码:((d{3,4})|d{3,4}-|s)?d{8}
224.
225. 31、提取信息中的中国电话号码(包括移动和固定电话):((d{3,4})|d{3,4}-|s)?d{7,14}
226.
227. 32、提取信息中的中国邮政编码:[1-9]{1}(d+){5}
228.
229. 33、提取信息中的浮点数(即小数):(-?d*).?d+
230.
231. 34、提取信息中的任何数字 :(-?d*)(.d+)?
232.
233. 35、IP:(d+).(d+).(d+).(d+)
234.
235. 36、电话区号:/^0d{2,3}$/
236.
237. 37、腾讯QQ号:^[1-9]*[1-9][0-9]*$
238.
239. 38、帐号(字母开头,允许5-16字节,允许字母数字下划线):^[a-zA-Z][a-zA-Z0-9_]{4,15}$
240.
241. 39、中文、英文、数字及下划线:^[u4e00-u9fa5_a-zA-Z0-9]+$
波比源码 » PHP常用正则表达式汇总
purchase levaquin online levaquin price
oral dutasteride order zofran 8mg pill order ondansetron 8mg sale
buy spironolactone 25mg without prescription order spironolactone generic buy fluconazole 200mg pill
ampicillin 500mg usa order erythromycin generic erythromycin 250mg without prescription
fildena online buy bimatoprost canada order methocarbamol
purchase sildenafil online purchase sildenafil buy estradiol 1mg online cheap
lamotrigine 200mg cheap prazosin cost brand tretinoin cream
tadalafil 20mg pill buy voltaren 50mg for sale buy voltaren 50mg
tadalafil 10mg uk new ed treatments order sildenafil pills
anastrozole 1mg usa Canadian healthcare viagra buy viagra 100mg online cheap
prednisone cost sildenafil otc viagra 25mg price
accutane 10mg tablet buy zithromax generic stromectol tablets buy online
doxycycline medication generic lasix 100mg buy generic furosemide
altace oral buy generic irbesartan 150mg buy astelin 10 ml for sale
buy catapres for sale order minocycline for sale tiotropium bromide 9 mcg price
purchase buspar pill order buspar online oxybutynin 5mg usa
alendronate 70mg over the counter order ibuprofen 600mg pills order famotidine 20mg online cheap
order benicar 20mg online cheap buy diamox without prescription cheap acetazolamide 250mg
imdur generic purchase micardis online cheap micardis 20mg for sale
buy bupropion 150 mg online cheap seroquel 50mg seroquel 100mg tablet
order molnunat generic molnupiravir online order prevacid 15mg cost
order imuran 100mcg generic imuran 100mcg ca buy viagra generic
cialis buy online prozac 40mg pills buy sildenafil 100mg pill
tadalafil 40mg without prescription cialis over the counter brand amantadine 100 mg
naltrexone 50mg ca buy naltrexone 50mg online cheap order aripiprazole 20mg online cheap
order dapsone 100 mg online cheap buy generic avlosulfon perindopril us
medroxyprogesterone 5mg over the counter biltricide 600 mg generic buy cyproheptadine 4 mg online cheap
order generic accutane 20mg isotretinoin 10mg cost order generic prednisone 40mg
nootropil cheap cheap sildenafil tablets order sildenafil 50mg
buy azithromycin 250mg generic buy azithromycin 500mg generic purchase neurontin online cheap
furosemide price purchase lasix for sale hydroxychloroquine 400mg price
order cialis 40mg online cheap order betamethasone online cheap buy clomipramine pills
order glycomet 500mg pills order atorvastatin 20mg for sale cialis online order
order zyprexa 10mg sale valsartan cheap purchase diovan online
order clozapine 100mg pills buy clozapine 100mg generic purchase decadron sale
buy sildenafil generic purchase lisinopril online order lisinopril 2.5mg
prilosec generic cheap custom research papers real money online blackjack
cheap lopressor lopressor without prescription vardenafil for sale
buy levitra 20mg online oral lyrica methylprednisolone 8mg over counter
essay helpers writing paper online viagra 150 mg
clomid drug online gambling free slots online
tadalafil 20mg price cheap generic cialis order viagra without prescription
xenical 60mg uk order generic orlistat order generic zovirax 400mg
cozaar for sale purchase topiramate sale topamax 100mg for sale
order baclofen 10mg online cheap buy tizanidine 2mg generic toradol 10mg pills
imitrex 50mg price imitrex over the counter dutasteride online order
buy ranitidine 300mg sale purchase ranitidine online cheap celecoxib sale
play blackjack online casino gambling hollywood casino online real money
buy tamsulosin 0.4mg sale buy spironolactone oral aldactone 100mg
order cialis 40mg online cipro order online cipro canada
flagyl 400mg generic flagyl 400mg pills buy bactrim sale
order keflex order keflex 250mg online buy erythromycin generic
buy tadalafil 10mg online cheap tadalafil drug viagra price
ceftin 500mg brand buy bimatoprost generic buy methocarbamol 500mg
free roulette games poker online play cialis 5mg ca
write my cover letter for me buy generic stromectol stromectol 12 mg
best online casino for real money buy ed medications online cialis 5mg without prescription
order zithromax 250mg online brand neurontin order neurontin for sale
furosemide price plaquenil drug buy plaquenil generic
cost fildena 100mg fildena 50mg sale rhinocort order online
oral deltasone buy vermox 100mg without prescription buy mebendazole pill
retin us buy avanafil 200mg without prescription order avana sale
tadacip 10mg without prescription order generic voltaren 50mg indocin 75mg oral
order lamisil without prescription trimox 250mg price amoxicillin over the counter
buy actos 15mg generic viagra usa sildenafil citrate 50 mg
ramipril price buy glimepiride online buy arcoxia 120mg pills
help me with my essay sulfasalazine cost order generic sulfasalazine 500mg
doxycycline tablet clindamycin oral cleocin 300mg ca
buy diamox cost imuran 25mg order azathioprine online cheap
buy coreg buy coreg 25mg generic buy amitriptyline 10mg sale
buy fosamax generic order furadantin without prescription motrin 400mg without prescription
order pamelor 25 mg online pamelor 25mg tablet buy paxil 20mg generic
pepcid 20mg ca buy tacrolimus remeron pills
buy tadacip 10mg pills buy plavix 150mg pill buy trimox 250mg online cheap
ropinirole 2mg cheap rocaltrol 0.25mg usa trandate 100mg pill
order fenofibrate pill order viagra 100mg without prescription viagra sildenafil 150mg
tadalafil order cheap viagra without prescription order sildenafil 100mg online cheap
cialis 40mg usa sale levitra buy ed medication
buy generic prednisone 10mg order generic accutane amoxicillin 250mg cheap
Hi, just required you to know I he added your site to my Google bookmarks due to your layout. But seriously, I believe your internet site has 1 in the freshest theme I??ve came across.onwin
order zofran 8mg for sale bactrim price brand sulfamethoxazole
buy antihistamine pills onlin buy levothyroxine pills augmentin oral
monodox drug buy vardenafil 20mg pills acyclovir price
avodart online order buy keflex 500mg generic orlistat 60mg generic
omnicef 300mg price pantoprazole 40mg sale protonix sale
order avlosulfon online cheap asacol 400mg sale buy atenolol pill
viagra uk sildenafil us buy cialis 20mg pills
oral levofloxacin 500mg levaquin buy online bupropion 150mg tablet
purchase cialis online cheap cialis 20mg pills causes of ed
modafinil 100mg pill where can i buy promethazine deltasone 20mg uk
accutane online order buy azithromycin 500mg pills buy azithromycin 250mg for sale
gabapentin usa order furosemide 100mg buy cheap doxycycline
albuterol 2mg canada order ventolin inhalator without prescription levoxyl uk
glucophage 500mg price order glucophage generic buy cheap norvasc
order orlistat 60mg generic purchase xenical zyloprim 300mg price
buy generic hyzaar over the counter losartan order online purchase topamax for sale
toradol 10mg tablet brand colchicine 0.5mg buy inderal 10mg generic
where to buy tamsulosin without a prescription spironolactone 100mg generic spironolactone for sale
buy duloxetine 20mg without prescription order generic glipizide 5mg where to buy nootropil without a prescription
progesterone 200mg for sale order olanzapine 10mg for sale zyprexa 10mg sale
buy simvastatin 10mg pills buy valacyclovir 1000mg viagra 100mg sale
order tegretol 200mg sale order generic carbamazepine 400mg buy lincomycin 500 mg online
purchase cefadroxil without prescription order finasteride 5mg pills propecia 5mg over the counter
order indocin 75mg sale buy generic terbinafine for sale buy cefixime medication
purchase nolvadex generic order nolvadex 10mg generic order cefuroxime pill
order trimox 500mg trimox over the counter oral biaxin
careprost usa desyrel medication purchase desyrel generic
buy sildenafil 50mg sale aurogra over the counter sildenafil uk
purchase lasix generic ventolin inhalator online buy order ventolin inhalator
buy vardenafil pill hydroxychloroquine canada buy hydroxychloroquine pill
buy altace 10mg generic order ramipril online etoricoxib 60mg oral
buy coreg no prescription buy cenforce pills for sale purchase chloroquine generic