详解JavaScript正则表达式中的global属性的使用
global是正则表达式对象的只读布尔属性。它指定是否一个特定的正则表达式进行全局匹配。否则它使用“g”属性创建。
语法
RegExpObject.global
下面是参数的详细信息:
NA返回值:
如果“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
简述JavaScript对传统文档对象模型的支持
这是将其在JavaScript语言早期版本中引入的模型。大家都被所有浏览器都支持,但只允许访问文件的某些关键部分,如表单,表单元素和图像。该模型提
简述JavaScript的正则表达式中test()方法的使用
test方法为正则表达式匹配的文本搜索字符串。如果找到匹配,则返回true;否则返回false。语法RegExpObject.test(string);下面是参数的详细信息:string:要搜索的
在JavaScript的正则表达式中使用exec()方法
exec方法为正则表达式匹配的文本搜索字符串。如果找到匹配,则返回结果数组;否则,返回null。语法RegExpObject.exec(string);下面是参数的详细信息:string: