Javascript RegExp.global属性
作者:--
发布时间:2019-11-20
评论:0
阅读:1
global是正则表达式对象的只读布尔属性。它指定是否一个特定的正则表达式进行全局匹配。否则它使用“g”属性创建。
语法
regexpobject.global
下面是参数的详细信息:
返回值:
如果“g”修改被设置返回“true”,否则返回“false”。
例子:
<html>
<head>
<title>javascript regexp global property</title>
</head>
<body>
<script type="text/javascript">
var re = new regexp( "string" );
if ( re.global ){
document.write("test1 - global property is set");
}else{
document.write("test1 - global property is not set");
}
re = new regexp( "string", "g" );
if ( re.global ){
document.write("<br />test2 - global property is set");
}else{
document.write("<br />test2 - global property is not set");
}
</script>
</body>
</html>
这将产生以下结果:
test1 - global property is not set
test2 - global property is set