Skip to content

Commit b32c33a

Browse files
committedDec 7, 2018
JS中正则表达式
1 parent 2b70c96 commit b32c33a

34 files changed

+351
-351
lines changed
 

‎JS中正则表达式/charAt.html

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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>

‎JS中正则表达式/match.html

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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>

‎JS中正则表达式/match2.html

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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>

‎JS中正则表达式/replace.html

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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>

‎JS中正则表达式/search.html

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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>

‎JS中正则表达式/split.html

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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>

‎JS中正则表达式/substring.html

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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 numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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 numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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>
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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>

‎JS中正则表达式/方括号.html

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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=/[apx]pc/g;
11+
12+
alert(str.match(re));
13+
</script>
14+
</head>
15+
<body>
16+
17+
</body>
18+
</html>
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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-z0-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>

‎JS中正则表达式/正则.html

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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 numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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 numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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>
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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>

‎JavaScript系列视频资料/智能社视频材料 - JS中的正则表达式/记录/charAt.html

-15
This file was deleted.

0 commit comments

Comments
 (0)