-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathrule2.html
380 lines (372 loc) · 19.3 KB
/
rule2.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
<!DOCTYPE html>
<!-- saved from url=(0037)http://www.jb51.net/tools/regexsc.htm -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="正则表达式速查表">
<title>正则表达式速查表</title>
<style type="text/css">
html, body {
margin:2px;
font-family:Verdana, Geneva, sans-serif;
font-size: 12px;;
}
table.wikitable {
background: none repeat scroll 0 0 #F9F9F9;
border: 1px solid #96B2D3;
border-collapse: collapse;
color: black;
}
.wikitable th, .wikitable td {
border: 1px solid #96B2D3;
}
.wikitable tr:hover{ background:#EAF0F7;}
.wikitable td{ line-height:20px;padding: 5px 8px;}
.wikitable th {
padding: 4px;
font-weight:normal;
background: none repeat scroll 0 0 #DBE5F1;
text-align: center;
}
p {
line-height: 1.5em;
margin: 0.4em 0 0.5em;
}
h2{ margin:0; font-weight:normal; text-align:center; background:#4F81BD; color:#FFF; font-family:"黑体";padding:8px 0; margin-bottom:5px; font-size:37px;}
.regex {font-family:"Courier New";}
</style>
<body style="zoom: 1;"><iframe frameborder="0" style="display: none;"></iframe><table width="101%" class="wikitable">
<tbody>
<tr>
<th width="8%" style="font-size:14px">字符</th>
<th width="92%" style="font-size:14px">描述</th>
</tr>
<tr>
<th>\</th>
<td>将下一个字符标记为一个特殊字符、或一个原义字符、或一个向后引用、或一个八进制转义符。例如,“<code>n</code>"匹配字符"<code>n</code>"。"<code>\n</code>"匹配一个换行符。串行"<code>\\</code>"匹配"<code>\</code>"而"<code>\(</code>"则匹配"<code>(</code>"。</td>
</tr>
<tr>
<th>^</th>
<td>匹配输入字符串的开始位置。如果设置了RegExp对象的Multiline属性,^也匹配“<code>\n</code>"或"<code>\r</code>"之后的位置。</td>
</tr>
<tr>
<th>$</th>
<td>匹配输入字符串的结束位置。如果设置了RegExp对象的Multiline属性,$也匹配“<code>\n</code>"或"<code>\r</code>"之前的位置。</td>
</tr>
<tr>
<th>*</th>
<td>匹配前面的子表达式零次或多次。例如,zo*能匹配“<code>z</code>"以及"<code>zoo</code>"。*等价于{0,}。</td>
</tr>
<tr>
<th>+</th>
<td>匹配前面的子表达式一次或多次。例如,“<code>zo+</code>"能匹配"<code>zo</code>"以及"<code>zoo</code>",但不能匹配"<code>z</code>"。+等价于{1,}。</td>
</tr>
<tr>
<th>?</th>
<td>匹配前面的子表达式零次或一次。例如,“<code>do(es)?</code>"可以匹配"<code>does</code>"或"<code>does</code>"中的"<code>do</code>"。?等价于{0,1}。</td>
</tr>
<tr>
<th>{<span style="font-family:Times New Roman; font-style:italic;">n</span>}</th>
<td><span style="font-family:Times New Roman; font-style:italic;">n</span>是一个非负整数。匹配确定的<span style="font-family:Times New Roman; font-style:italic;">n</span>次。例如,“<code>o{2}</code>"不能匹配"<code>Bob</code>"中的"<code>o</code>",但是能匹配"<code>food</code>"中的两个o。</td>
</tr>
<tr>
<th>{<span style="font-family:Times New Roman; font-style:italic;">n</span>,}</th>
<td><span style="font-family:Times New Roman; font-style:italic;">n</span>是一个非负整数。至少匹配<span style="font-family:Times New Roman; font-style:italic;">n</span>次。例如,“<code>o{2,}</code>"不能匹配"<code>Bob</code>"中的"<code>o</code>",但能匹配"<code>foooood</code>"中的所有o。"<code>o{1,}</code>"等价于"<code>o+</code>"。"<code>o{0,}</code>"则等价于"<code>o*</code>"。</td>
</tr>
<tr>
<th>{<span style="font-family:Times New Roman; font-style:italic;">n</span>,<span style="font-family:Times New Roman; font-style:italic;">m</span>}</th>
<td><span style="font-family:Times New Roman; font-style:italic;">m</span>和<span style="font-family:Times New Roman; font-style:italic;">n</span>均为非负整数,其中<span style="font-family:Times New Roman; font-style:italic;">n</span><=<span style="font-family:Times New Roman; font-style:italic;">m</span>。最少匹配<span style="font-family:Times New Roman; font-style:italic;">n</span>次且最多匹配<span style="font-family:Times New Roman; font-style:italic;">m</span>次。例如,“<code>o{1,3}</code>"将匹配"<code>fooooood</code>"中的前三个o。"<code>o{0,1}</code>"等价于"<code>o?</code>"。请注意在逗号和两个数之间不能有空格。</td>
</tr>
<tr>
<th>?</th>
<td>当该字符紧跟在任何一个其他限制符(*,+,?,{<span style="font-family:Times New Roman; font-style:italic;">n</span>},{<span style="font-family:Times New Roman; font-style:italic;">n</span>,},{<span style="font-family:Times New Roman; font-style:italic;">n</span>,<span style="font-family:Times New Roman; font-style:italic;">m</span>})后面时,匹配模式是非贪婪的。非贪婪模式尽可能少的匹配所搜索的字符串,而默认的贪婪模式则尽可能多的匹配所搜索的字符串。例如,对于字符串“<code>oooo</code>","<code>o+?</code>"将匹配单个"<code>o</code>",而"<code>o+</code>"将匹配所有"<code>o</code>"。</td>
</tr>
<tr>
<th>.</th>
<td>匹配除“<code>\</code><span style="font-family:Times New Roman; font-style:italic;"><code>n</code></span>"之外的任何单个字符。要匹配包括"<code>\</code><span style="font-family:Times New Roman; font-style:italic;"><code>n</code></span>"在内的任何字符,请使用像"<code>(.|\n)</code>"的模式。</td>
</tr>
<tr>
<th>(pattern)</th>
<td>匹配pattern并获取这一匹配。所获取的匹配可以从产生的Matches集合得到,在VBScript中使用SubMatches集合,在JScript中则使用$0…$9属性。要匹配圆括号字符,请使用“<code>\(</code>"或"<code>\)</code>"。</td>
</tr>
<tr>
<th>(?:pattern)</th>
<td>匹配pattern但不获取匹配结果,也就是说这是一个非获取匹配,不进行存储供以后使用。这在使用或字符“<code>(|)</code>"来组合一个模式的各个部分是很有用。例如"<code>industr(?:y|ies)</code>"就是一个比"<code>industry|industries</code>"更简略的表达式。</td>
</tr>
<tr>
<th>(?=pattern)</th>
<td>正向肯定预查,在任何匹配pattern的字符串开始处匹配查找字符串。这是一个非获取匹配,也就是说,该匹配不需要获取供以后使用。例如,“<code>Windows(?=95|98|NT|2000)</code>"能匹配"<code>Windows2000</code>"中的"<code>Windows</code>",但不能匹配"<code>Windows3.1</code>"中的"<code>Windows</code>"。预查不消耗字符,也就是说,在一个匹配发生后,在最后一次匹配之后立即开始下一次匹配的搜索,而不是从包含预查的字符之后开始。</td>
</tr>
<tr>
<th>(?!pattern)</th>
<td>正向否定预查,在任何不匹配pattern的字符串开始处匹配查找字符串。这是一个非获取匹配,也就是说,该匹配不需要获取供以后使用。例如“<code>Windows(?!95|98|NT|2000)</code>"能匹配"<code>Windows3.1</code>"中的"<code>Windows</code>",但不能匹配"<code>Windows2000</code>"中的"<code>Windows</code>"。预查不消耗字符,也就是说,在一个匹配发生后,在最后一次匹配之后立即开始下一次匹配的搜索,而不是从包含预查的字符之后开始</td>
</tr>
<tr>
<th>(?<=pattern)</th>
<td>反向肯定预查,与正向肯定预查类拟,只是方向相反。例如,“<code>(?<=95|98|NT|2000)Windows</code>"能匹配"<code>2000Windows</code>"中的"<code>Windows</code>",但不能匹配"<code>3.1Windows</code>"中的"<code>Windows</code>"。</td>
</tr>
<tr>
<th>(?<!pattern)</th>
<td>反向否定预查,与正向否定预查类拟,只是方向相反。例如“<code>(?<!95|98|NT|2000)Windows</code>"能匹配"<code>3.1Windows</code>"中的"<code>Windows</code>",但不能匹配"<code>2000Windows</code>"中的"<code>Windows</code>"。</td>
</tr>
<tr>
<th>x|y</th>
<td>匹配x或y。例如,“<code>z|food</code>"能匹配"<code>z</code>"或"<code>food</code>"。"<code>(z|f)ood</code>"则匹配"<code>zood</code>"或"<code>food</code>"。</td>
</tr>
<tr>
<th>[xyz]</th>
<td>字符集合。匹配所包含的任意一个字符。例如,“<code>[abc]</code>"可以匹配"<code>plain</code>"中的"<code>a</code>"。</td>
</tr>
<tr>
<th>[^xyz]</th>
<td>负值字符集合。匹配未包含的任意字符。例如,“<code>[^abc]</code>"可以匹配"<code>plain</code>"中的"<code>p</code>"。</td>
</tr>
<tr>
<th>[a-z]</th>
<td>字符范围。匹配指定范围内的任意字符。例如,“<code>[a-z]</code>"可以匹配"<code>a</code>"到"<code>z</code>"范围内的任意小写字母字符。</td>
</tr>
<tr>
<th>[^a-z]</th>
<td>负值字符范围。匹配任何不在指定范围内的任意字符。例如,“<code>[^a-z]</code>"可以匹配任何不在"<code>a</code>"到"<code>z</code>"范围内的任意字符。</td>
</tr>
<tr>
<th>\b</th>
<td>匹配一个单词边界,也就是指单词和空格间的位置。例如,“<code>er\b</code>"可以匹配"<code>never</code>"中的"<code>er</code>",但不能匹配"<code>verb</code>"中的"<code>er</code>"。</td>
</tr>
<tr>
<th>\B</th>
<td>匹配非单词边界。“<code>er\B</code>"能匹配"<code>verb</code>"中的"<code>er</code>",但不能匹配"<code>never</code>"中的"<code>er</code>"。</td>
</tr>
<tr>
<th>\cx</th>
<td>匹配由x指明的控制字符。例如,\cM匹配一个Control-M或回车符。x的值必须为A-Z或a-z之一。否则,将c视为一个原义的“<code>c</code>"字符。</td>
</tr>
<tr>
<th>\d</th>
<td>匹配一个数字字符。等价于[0-9]。</td>
</tr>
<tr>
<th>\D</th>
<td>匹配一个非数字字符。等价于[^0-9]。</td>
</tr>
<tr>
<th>\f</th>
<td>匹配一个换页符。等价于\x0c和\cL。</td>
</tr>
<tr>
<th>\n</th>
<td>匹配一个换行符。等价于\x0a和\cJ。</td>
</tr>
<tr>
<th>\r</th>
<td>匹配一个回车符。等价于\x0d和\cM。</td>
</tr>
<tr>
<th>\s</th>
<td>匹配任何空白字符,包括空格、制表符、换页符等等。等价于[ \f\n\r\t\v]。</td>
</tr>
<tr>
<th>\S</th>
<td>匹配任何非空白字符。等价于[^ \f\n\r\t\v]。</td>
</tr>
<tr>
<th>\t</th>
<td>匹配一个制表符。等价于\x09和\cI。</td>
</tr>
<tr>
<th>\v</th>
<td>匹配一个垂直制表符。等价于\x0b和\cK。</td>
</tr>
<tr>
<th>\w</th>
<td>匹配包括下划线的任何单词字符。等价于“<code>[A-Za-z0-9_]</code>"。</td>
</tr>
<tr>
<th>\W</th>
<td>匹配任何非单词字符。等价于“<code>[^A-Za-z0-9_]</code>"。</td>
</tr>
<tr>
<th>\x<span style="font-family:Times New Roman; font-style:italic;">n</span></th>
<td>匹配<span style="font-family:Times New Roman; font-style:italic;">n</span>,其中<span style="font-family:Times New Roman; font-style:italic;">n</span>为十六进制转义值。十六进制转义值必须为确定的两个数字长。例如,“<code>\x41</code>"匹配"<code>A</code>"。"<code>\x041</code>"则等价于"<code>\x04&1</code>"。正则表达式中可以使用ASCII编码。.</td>
</tr>
<tr>
<th>\<span style="font-family:Times New Roman; font-style:italic;">num</span></th>
<td>匹配<span style="font-family:Times New Roman; font-style:italic;">num</span>,其中<span style="font-family:Times New Roman; font-style:italic;">num</span>是一个正整数。对所获取的匹配的引用。例如,“<code>(.)\1</code>"匹配两个连续的相同字符。</td>
</tr>
<tr>
<th>\<span style="font-family:Times New Roman; font-style:italic;">n</span></th>
<td>标识一个八进制转义值或一个向后引用。如果\<span style="font-family:Times New Roman; font-style:italic;">n</span>之前至少<span style="font-family:Times New Roman; font-style:italic;">n</span>个获取的子表达式,则<span style="font-family:Times New Roman; font-style:italic;">n</span>为向后引用。否则,如果<span style="font-family:Times New Roman; font-style:italic;">n</span>为八进制数字(0-7),则<span style="font-family:Times New Roman; font-style:italic;">n</span>为一个八进制转义值。</td>
</tr>
<tr>
<th>\<span style="font-family:Times New Roman; font-style:italic;">nm</span></th>
<td>标识一个八进制转义值或一个向后引用。如果\<span style="font-family:Times New Roman; font-style:italic;">nm</span>之前至少有<span style="font-family:Times New Roman; font-style:italic;">nm</span>个获得子表达式,则<span style="font-family:Times New Roman; font-style:italic;">nm</span>为向后引用。如果\<span style="font-family:Times New Roman; font-style:italic;">nm</span>之前至少有<span style="font-family:Times New Roman; font-style:italic;">n</span>个获取,则<span style="font-family:Times New Roman; font-style:italic;">n</span>为一个后跟文字<span style="font-family:Times New Roman; font-style:italic;">m</span>的向后引用。如果前面的条件都不满足,若<span style="font-family:Times New Roman; font-style:italic;">n</span>和<span style="font-family:Times New Roman; font-style:italic;">m</span>均为八进制数字(0-7),则\<span style="font-family:Times New Roman; font-style:italic;">nm</span>将匹配八进制转义值<span style="font-family:Times New Roman; font-style:italic;">nm</span>。</td>
</tr>
<tr>
<th>\<span style="font-family:Times New Roman; font-style:italic;">nml</span></th>
<td>如果<span style="font-family:Times New Roman; font-style:italic;">n</span>为八进制数字(0-3),且<span style="font-family:Times New Roman; font-style:italic;">m和l</span>均为八进制数字(0-7),则匹配八进制转义值<span style="font-family:Times New Roman; font-style:italic;">nm</span>l。</td>
</tr>
<tr>
<th>\u<span style="font-family:Times New Roman; font-style:italic;">n</span></th>
<td>匹配<span style="font-family:Times New Roman; font-style:italic;">n</span>,其中<span style="font-family:Times New Roman; font-style:italic;">n</span>是一个用四个十六进制数字表示的Unicode字符。例如,\u00A9匹配版权符号(©)。</td>
</tr>
</tbody>
</table>
<br>
<h2>常用正则表达式</h2>
<table class="wikitable" width="100%">
<tbody><tr>
<th width="8%">用户名</th>
<td width="92%">/^[a-z0-9_-]{3,16}$/</td>
</tr>
<tr>
<th scope="row">密码</th>
<td>/^[a-z0-9_-]{6,18}$/</td>
</tr>
<tr>
<th scope="row">密码2</th>
<td><span class="regex">(?=^.{8,}$)(?=.*\d)(?=.*\W+)(?=.*[A-Z])(?=.*[a-z])(?!.*\n).*$</span> (由数字/大写字母/小写字母/标点符号组成,四种都必有,8位以上) </td>
</tr>
<tr>
<th scope="row">十六进制值</th>
<td>/^#?([a-f0-9]{6}|[a-f0-9]{3})$/</td>
</tr>
<tr>
<th scope="row">电子邮箱</th>
<td>/^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/<br>
/^[a-z\d]+(\.[a-z\d]+)*@([\da-z](-[\da-z])?)+(\.{1,2}[a-z]+)+$/或<span class="regex">\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*</span></td>
</tr>
<tr>
<th scope="row">URL</th>
<td>/^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/ 或 <span class="regex">[a-zA-z]+://[^\s]*</span></td>
</tr>
<tr>
<th scope="row">IP 地址</th>
<td>/((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?)/<br>
/^(?:(?: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]?)$/ 或 <span class="regex">((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?)</span></td>
</tr>
<tr>
<th scope="row">HTML 标签</th>
<td>/^<([a-z]+)([^<]+)*(?:>(.*)<\/\1>|\s+\/>)$/或<span class="regex"><(.*)(.*)>.*<\/\1>|<(.*) \/></span></td>
</tr>
<tr>
<th scope="row">删除代码\\注释</th>
<td>(?<!http:|\S)//.*$</td>
</tr>
<!-- <tr>
<th scope="row"> </th>
<td> </td>
</tr>-->
<tr>
<th scope="row">匹配双字节字符(包括汉字在内)</th>
<td>[^\x00-\xff]</td>
</tr>
<tr>
<th scope="row">汉字(字符)</th>
<td>[\u4e00-\u9fa5]</td>
</tr>
<tr>
<th scope="row">Unicode编码中的汉字范围</th>
<td>/^[\u2E80-\u9FFF]+$/</td>
</tr>
<tr>
<th scope="row">中文及全角标点符号(字符)</th>
<td>[\u3000-\u301e\ufe10-\ufe19\ufe30-\ufe44\ufe50-\ufe6b\uff01-\uffee]</td>
</tr>
<tr>
<th scope="row">日期(年-月-日)</th>
<td>(\d{4}|\d{2})-((0?([1-9]))|(1[1|2]))-((0?[1-9])|([12]([1-9]))|(3[0|1]))</td>
</tr>
<tr>
<th scope="row">日期(月/日/年)</th>
<td>((0?[1-9]{1})|(1[1|2]))/(0?[1-9]|([12][1-9])|(3[0|1]))/(\d{4}|\d{2})</td>
</tr>
<tr>
<th scope="row">时间(小时:分钟, 24小时制)</th>
<td>((1|0?)[0-9]|2[0-3]):([0-5][0-9])</td>
</tr>
<tr>
<th scope="row">中国大陆固定电话号码</th>
<td>(\d{4}-|\d{3}-)?(\d{8}|\d{7})</td>
</tr>
<tr>
<th scope="row">中国大陆手机号码
</th><td>1\d{10}</td>
</tr>
<tr>
<th scope="row">中国大陆邮政编码
</th><td>[1-9]\d{5}</td>
</tr>
<tr>
<th scope="row">中国大陆身份证号(15位或18位)
</th><td>\d{15}(\d\d[0-9xX])?</td>
</tr>
<tr>
<th scope="row">非负整数(正整数或零)
</th><td>\d+</td>
</tr>
<tr>
<th scope="row">正整数
</th><td>[0-9]*[1-9][0-9]*</td>
</tr>
<tr>
<th scope="row">负整数
</th><td>-[0-9]*[1-9][0-9]*</td>
</tr>
<tr>
<th scope="row">整数
</th><td>-?\d+</td>
</tr>
<tr>
<th scope="row">小数
</th><td>(-?\d+)(\.\d+)?</td>
</tr>
<tr>
<th scope="row">空白行</th>
<td>\n\s*\r 或者 \n\n(editplus) 或者 ^[\s\S ]*\n <br></td>
</tr>
<tr>
<th scope="row"><span class="regex">QQ号码</span></th>
<td><span class="regex">[1-9]\d{4,}</span></td>
</tr>
<tr>
<th scope="row">不包含abc的单词</th>
<td><span class="regex">\b((?!abc)\w)+\b</span></td>
</tr>
<tr>
<th scope="row">匹配首尾空白字符</th>
<td>^\s*|\s*$</td>
</tr>
<tr>
<th scope="row">编辑常用</th>
<td><div>以下是针对特殊中文的一些替换(editplus)</div>
<div><br>
</div>
<div>^[0-9].*\n </div>
<div><br>
</div>
<div>^[^第].*\n </div>
<div><br>
</div>
<div>^[习题].*\n</div>
<div><br>
</div>
<div>^[\s\S ]*\n </div>
<div>^[0-9]*\. </div>
<div>^[\s\S ]*\n </div>
<div><p[^<>*]></div>
<div>href="javascript:if\(confirm\('(.*?)'\)\)window\.location='(.*?)'"</div>
<div><span style=".[^"]*rgb\(255,255,255\)">.[^<>]*</span><br>
<br>
<DIV class=xs0>[\s\S]*?</DIV></div></td>
</tr>
<tr>
<th scope="row"> </th>
<td> </td>
</tr>
<tr>
<th scope="row"> </th>
<td> </td>
</tr>
</tbody></table>
</body></html>