File tree 34 files changed +351
-351
lines changed
JavaScript系列视频资料/智能社视频材料 - JS中的正则表达式
34 files changed +351
-351
lines changed Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html lang ="en ">
3
+ < head >
4
+ < meta charset ="UTF-8 ">
5
+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
6
+ < meta http-equiv ="X-UA-Compatible " content ="ie=edge ">
7
+ < title > Document</ title >
8
+ < script >
9
+ var str = 'abcdef' ;
10
+
11
+ alert ( str . charAt ( 3 ) ) ;
12
+ </ script >
13
+
14
+ </ head >
15
+ < body >
16
+
17
+ </ body >
18
+ </ html >
Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html lang ="en ">
3
+ < head >
4
+ < meta charset ="UTF-8 ">
5
+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
6
+ < meta http-equiv ="X-UA-Compatible " content ="ie=edge ">
7
+ < title > Document</ title >
8
+ < script >
9
+ var str = 'asdf 34 656 cvs33' ;
10
+ var re = / \d / g;
11
+
12
+ alert ( str . match ( re ) ) ;
13
+ </ script >
14
+ </ head >
15
+ < body >
16
+
17
+ </ body >
18
+ </ html >
Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html lang ="en ">
3
+ < head >
4
+ < meta charset ="UTF-8 ">
5
+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
6
+ < meta http-equiv ="X-UA-Compatible " content ="ie=edge ">
7
+ < title > Document</ title >
8
+ < script >
9
+ var str = 'asdf 34 656 cvs33' ;
10
+ var re = / \d + / g;
11
+
12
+ alert ( str . match ( re ) ) ;
13
+ </ script >
14
+ </ head >
15
+ < body >
16
+
17
+ </ body >
18
+ </ html >
Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html lang ="en ">
3
+ < head >
4
+ < meta charset ="UTF-8 ">
5
+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
6
+ < meta http-equiv ="X-UA-Compatible " content ="ie=edge ">
7
+ < title > Document</ title >
8
+ < script >
9
+ var str = 'abc aaa erw' ;
10
+ var re = / a / g;
11
+
12
+ alert ( str . replace ( re , 0 ) ) ;
13
+
14
+ </ script >
15
+ </ head >
16
+ < body >
17
+
18
+ </ body >
19
+ </ html >
Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html lang ="en ">
3
+ < head >
4
+ < meta charset ="UTF-8 ">
5
+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
6
+ < meta http-equiv ="X-UA-Compatible " content ="ie=edge ">
7
+ < title > Document</ title >
8
+ < script >
9
+ var str = 'abcdef' ;
10
+
11
+ alert ( str . search ( 'b' ) ) ;
12
+ </ script >
13
+
14
+ </ head >
15
+ < body >
16
+
17
+ </ body >
18
+ </ html >
Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html lang ="en ">
3
+ < head >
4
+ < meta charset ="UTF-8 ">
5
+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
6
+ < meta http-equiv ="X-UA-Compatible " content ="ie=edge ">
7
+ < title > Document</ title >
8
+ < script >
9
+ var str = "12-56-aaa-89" ;
10
+ var arr = str . split ( '-' ) ;
11
+
12
+ alert ( arr ) ;
13
+ </ script >
14
+ </ head >
15
+ < body >
16
+
17
+ </ body >
18
+ </ html >
Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html lang ="en ">
3
+ < head >
4
+ < meta charset ="UTF-8 ">
5
+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
6
+ < meta http-equiv ="X-UA-Compatible " content ="ie=edge ">
7
+ < title > Document</ title >
8
+ < script >
9
+ var str = 'abcdef' ;
10
+
11
+ alert ( str . substring ( 2 , 5 ) ) ;
12
+ alert ( str . substring ( 1 ) ) ;
13
+ </ script >
14
+
15
+ </ head >
16
+ < body >
17
+
18
+ </ body >
19
+ </ html >
Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html lang ="en ">
3
+ < head >
4
+ < meta charset ="UTF-8 ">
5
+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
6
+ < meta http-equiv ="X-UA-Compatible " content ="ie=edge ">
7
+ < title > Document</ title >
8
+ < script >
9
+ var str = '12 fff 87 er3334 233 -=-=fa80' ;
10
+ var arr = [ ] ;
11
+ var tmp = '' ;
12
+
13
+ for ( var i = 0 ; i < str . length ; i ++ )
14
+ {
15
+ if ( str . charAt ( i ) >= '0' && str . charAt ( i ) <= '9' )
16
+ {
17
+ tmp += str . charAt ( i ) ;
18
+ }
19
+ else
20
+ {
21
+ if ( tmp )
22
+ {
23
+ arr . push ( tmp ) ;
24
+ tmp = '' ;
25
+ }
26
+ }
27
+ }
28
+ if ( tmp )
29
+ {
30
+ arr . push ( tmp ) ;
31
+ tmp = '' ;
32
+ }
33
+ alert ( arr ) ;
34
+
35
+ </ script >
36
+ </ head >
37
+ < body >
38
+
39
+ </ body >
40
+ </ html >
Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html lang ="en ">
3
+ < head >
4
+ < meta charset ="UTF-8 ">
5
+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
6
+ < meta http-equiv ="X-UA-Compatible " content ="ie=edge ">
7
+ < title > Document</ title >
8
+ < script >
9
+ var str = '12 fff 87 er3334 233 -=-=fa80' ;
10
+
11
+ //alert(str.match(/\d+/g));
12
+ alert ( str . match ( / [ 0 - 9 ] + / g) ) ;
13
+
14
+ </ script >
15
+ </ head >
16
+ < body >
17
+
18
+ </ body >
19
+ </ html >
Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html lang ="en ">
3
+ < head >
4
+ < meta charset ="UTF-8 ">
5
+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
6
+ < meta http-equiv ="X-UA-Compatible " content ="ie=edge ">
7
+ < title > Document</ title >
8
+ < script >
9
+ window . onload = function ( )
10
+ {
11
+ var oTxt1 = document . getElementById ( 'txt1' ) ;
12
+ var oTxt2 = document . getElementById ( 'txt2' ) ;
13
+ var oBtn = document . getElementById ( 'btn1' ) ;
14
+
15
+ oBtn . onclick = function ( )
16
+ {
17
+ var re = / 北 京 | 百 度 | 淘 宝 / g;
18
+
19
+ oTxt2 . value = oTxt1 . value . replace ( re , '****' ) ;
20
+ }
21
+ }
22
+ </ script >
23
+ </ head >
24
+ < body >
25
+ < textarea id ="txt1 " rows ="10 " cols ="40 "> </ textarea > < br >
26
+ < input id ="btn1 " type ="button " value ="过滤 " /> < br >
27
+ < textarea id ="txt2 " rows ="10 " cols ="40 "> </ textarea >
28
+ </ body >
29
+ </ html >
Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html lang ="en ">
3
+ < head >
4
+ < meta charset ="UTF-8 ">
5
+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
6
+ < meta http-equiv ="X-UA-Compatible " content ="ie=edge ">
7
+ < title > Document</ title >
8
+ < script >
9
+ var str = 'apc xpc ppc bpc spc tpc' ;
10
+ var re = / [ a p x ] p c / g;
11
+
12
+ alert ( str . match ( re ) ) ;
13
+ </ script >
14
+ </ head >
15
+ < body >
16
+
17
+ </ body >
18
+ </ html >
Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html lang ="en ">
3
+ < head >
4
+ < meta charset ="UTF-8 ">
5
+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
6
+ < meta http-equiv ="X-UA-Compatible " content ="ie=edge ">
7
+ < title > Document</ title >
8
+ < script >
9
+ window . onload = function ( )
10
+ {
11
+ var oTxt = document . getElementById ( 'txt1' ) ;
12
+ var oBtn = document . getElementById ( 'btn1' ) ;
13
+
14
+ oBtn . onclick = function ( )
15
+ {
16
+ var re = / ^ \w + @ [ a - z 0 - 9 ] + \. [ a - z ] + $ / i;
17
+
18
+ if ( re . test ( oTxt . value ) )
19
+ {
20
+ alert ( '合法的邮箱' ) ;
21
+ }
22
+ else {
23
+ alert ( '你丫写错了' ) ;
24
+ }
25
+
26
+ }
27
+ }
28
+ </ script >
29
+ </ head >
30
+ < body >
31
+ < input type ="text " id ="txt1 "/>
32
+ < input type ="button " value ="校验 " id ="btn1 "/>
33
+ </ body >
34
+ </ html >
Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html lang ="en ">
3
+ < head >
4
+ < meta charset ="UTF-8 ">
5
+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
6
+ < meta http-equiv ="X-UA-Compatible " content ="ie=edge ">
7
+ < title > Document</ title >
8
+ < script >
9
+ var str = 'adsf 43 23 vcxzxcv' ;
10
+ var re = / \d / ;
11
+
12
+ alert ( str . search ( re ) ) ;
13
+ </ script >
14
+ </ head >
15
+ < body >
16
+
17
+ </ body >
18
+ </ html >
Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html lang ="en ">
3
+ < head >
4
+ < meta charset ="UTF-8 ">
5
+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
6
+ < meta http-equiv ="X-UA-Compatible " content ="ie=edge ">
7
+ < title > Document</ title >
8
+ < script >
9
+ var re = new RegExp ( 'a' , 'i' ) ;
10
+ var str = 'Abcdef' ;
11
+
12
+ alert ( str . search ( re ) ) ;
13
+ </ script >
14
+ </ head >
15
+ < body >
16
+
17
+ </ body >
18
+ </ html >
Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html lang ="en ">
3
+ < head >
4
+ < meta charset ="UTF-8 ">
5
+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
6
+ < meta http-equiv ="X-UA-Compatible " content ="ie=edge ">
7
+ < title > Document</ title >
8
+ < script >
9
+ var re = / a / i; //i,忽略大小写
10
+ var str = 'Abcdef' ;
11
+
12
+ alert ( str . search ( re ) ) ;
13
+ </ script >
14
+ </ head >
15
+ < body >
16
+
17
+ </ body >
18
+ </ html >
Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html lang ="en ">
3
+ < head >
4
+ < meta charset ="UTF-8 ">
5
+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
6
+ < meta http-equiv ="X-UA-Compatible " content ="ie=edge ">
7
+ < title > Document</ title >
8
+ < script >
9
+ window . onload = function ( )
10
+ {
11
+ var oTxt1 = document . getElementById ( 'txt1' ) ;
12
+ var oTxt2 = document . getElementById ( 'txt2' ) ;
13
+ var oBtn = document . getElementById ( 'btn1' ) ;
14
+
15
+ oBtn . onclick = function ( )
16
+ {
17
+ var re = / < [ ^ < > ] / g;
18
+
19
+ oTxt2 . value = oTxt1 . value . replace ( re , '' ) ;
20
+ }
21
+ }
22
+ </ script >
23
+ </ head >
24
+ < body >
25
+ < textarea id ="txt1 " rows ="10 " cols ="40 "> </ textarea > < br >
26
+ < input id ="btn1 " type ="button " value ="转换 " /> < br >
27
+ < textarea id ="txt2 " rows ="10 " cols ="40 "> </ textarea >
28
+ </ body >
29
+ </ html >
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments