JavaScript source 属性


定义和用法

source 属性用于返回模式匹配所用的文本。

该文本不包括正则表达式直接量使用的定界符,也不包括标志 g、i、m。

语法
  1. RegExpObject.source

实例

在下面的例子中,我们将获得用于模式匹配的文本:

  1. <html>
  2. <body>
  3. <script type="text/javascript">
  4. var str = "Visit Cankaoshouce.com";
  5. var patt1 = new RegExp("Can","g");
  6. document.write("The regular expression is: " + patt1.source);
  7. </script>
  8. </body>
  9. </html>

分类导航