返回到:JavaScript对象:JavaScript RegExp 对象
定义和用法
^n量词匹配任何开头为 n 的字符串。
语法
new RegExp("^n")
或者
/^n/
实例
对字符串开头的 “Is” 进行全局搜索:
var str="Is this his";
var patt1=/^Is/g;
DEMO:
HTML
x
16
16
1
2
<html>
3
<head>
4
<meta charset="utf-8">
5
<title>Web176教程(Web176.com)</title>
6
</head>
7
<body>
8
9
<script>
10
var str="Is this his";
11
var patt1=/^Is/g;
12
document.write(str.match(patt1));
13
14
</script>
15
</body>
16
</html>
阅读剩余 29%
作者:terry,如若转载,请注明出处:https://www.web176.com/javascriptbook/jsarrtips/2892.html