JavaScript之正則表達式入门
<html>
<head><title>Js String 正則表達式</title>
<script>
//边界符 js 中直接定义须要边界符// java里面不须要边界符
var re = /abc/;//匹配abc的
document.write(re.test("abcdabc")+","+re.test("XXXC")+"<br/>");
re =/\/abc\//;
//匹配/abc/
document.write(re.test("/abc/")+","+re.test("addd")+","+"<br/>");
//不须要边界符
//匹配abc的
var regex = new RegExp("abc");
document.write(regex.test("abc")+","+regex.test("abcdeabc")+","+regex.test("xxxxadcabcc")+"<br/>");
</script>
</head>
<body>
</body>
</html>
<head><title>Js String 正則表達式</title>
<script>
//边界符 js 中直接定义须要边界符// java里面不须要边界符
var re = /abc/;//匹配abc的
document.write(re.test("abcdabc")+","+re.test("XXXC")+"<br/>");
re =/\/abc\//;
//匹配/abc/
document.write(re.test("/abc/")+","+re.test("addd")+","+"<br/>");
//不须要边界符
//匹配abc的
var regex = new RegExp("abc");
document.write(regex.test("abc")+","+regex.test("abcdeabc")+","+regex.test("xxxxadcabcc")+"<br/>");
</script>
</head>
<body>
</body>
</html>