返回在模式匹配期间找到的,所存储的最近的九个部分。 只读。

 
 
  1. RegExp.$n
参数

 
 
RegExp

始终为全局 RegExp 对象。

n

1 至 9 之间的任意整数。

备注

 
 

每当产生一个带括号的成功匹配时,$1...$9 属性的值就被修改。 可以在一个正则表达式模式中指定任意多个带括号的子匹配,但只能存储最新的九个。

示例

 
 

下面的示例执行正则表达式搜索。 它显示了全局 RegExp 对象中的匹配项和子匹配项。 子匹配项是 $1…$9 属性中包含的成功的带括号匹配项。 该示例还显示了由 exec 方法返回的数组中的匹配项和子匹配项。

 
  1. var newLine = "<br />";
  2.  
  3. var re = /(\w+)@(\w+)\.(\w+)/g
  4. var src = "Please send mail to george@contoso.com and someone@example.com. Thanks!"
  5.  
  6. var result;
  7. var s = "";
  8.  
  9. // Get the first match.
  10. result = re.exec(src);
  11.  
  12. while (result != null) {
  13. // Show the entire match.
  14. s += newLine;
  15.  
  16. // Show the match and submatches from the RegExp global object.
  17. s += "RegExp.lastMatch: " + RegExp.lastMatch + newLine;
  18. s += "RegExp.$1: " + RegExp.$1 + newLine;
  19. s += "RegExp.$2: " + RegExp.$2 + newLine;
  20. s += "RegExp.$3: " + RegExp.$3 + newLine;
  21.  
  22. // Show the match and submatches from the array that is returned
  23. // by the exec method.
  24. for (var index = 0; index < result.length; index++) {
  25. s += index + ": ";
  26. s += result[index];
  27. s += newLine;
  28. }
  29.  
  30. // Get the next match.
  31. result = re.exec(src);
  32. }
  33. document.write(s);
  34.  
  35. // Output:
  36. // RegExp.lastMatch: george@contoso.com
  37. // RegExp.$1: george
  38. // RegExp.$2: contoso
  39. // RegExp.$3: com
  40. // 0: george@contoso.com
  41. // 1: george
  42. // 2: contoso
  43. // 3: com
  44.  
  45. // RegExp.lastMatch: someone@example.com
  46. // RegExp.$1: someone
  47. // RegExp.$2: example
  48. // RegExp.$3: com
  49. // 0: someone@example.com
  50. // 1: someone
  51. // 2: example
  52. // 3: com
要求

 
 

在以下文档模式中受支持:Quirks、Internet Explorer 6 标准模式、Internet Explorer 7 标准模式、Internet Explorer 8 标准模式、Internet Explorer 9 标准模式、Internet Explorer 10 标准模式和 Internet Explorer 11 标准模式。此外,也在应用商店应用(Windows 8 和 Windows Phone 8.1)中受支持。请参阅版本信息

适用于RegExp 对象 (JavaScript)

随机推荐

  1. Connecting to Shares And Common Shares

    Now that you have these shares, how do people use them? Assuming that you have a share called Apps o ...

  2. jd算法大赛 一个user_id只需映射到一个sku_id, 但是一个sku_id能否映射到多个user_id

    0-购买预测 w 任务目标 提交user_id-->sku_id (1->1,但反向呢?) 实际操作: 0- 行为表中的type值加权为一个购买意向值0(性别.年龄,不干扰/或加权) 品类 ...

  3. Struts 上传文件

    1. 客户端注意事项 method="post" enctype="multipart/form-data" <input type="file ...

  4. 标准编译安装(cmake make)

    为什么要编译安装?因为根据需求可以个性化定制功能. 关键是阅读cmakelist,看都有哪些依赖,都有哪些选项可用,哪些选项是自己可以配置的. 一般流程: mkdir build cd build c ...

  5. 缓存在中间件中的应用机制(Django)

    缓存在中间件中的应用机制(Django) (右键图片:在新标签页中打开连接)

  6. 23种设计模式UML图

  7. Python 模块之 pyexcel_xls

    一.适用场景 在很多数据统计或者数据分析的场景中,我们都会使用到excel: 在一些系统中我们也会使用excel作为数据导入和导出的方式,那么如何使用python加以辅助我们快速进行excel数据做更 ...

  8. Python基础-面向对象2

    一.成员修饰符 共有成员 私有成员:创建方式在成员之前加两个下划线,私有成员无法直接访问,只能间接访问 子类不能继承父类的私有属相私有普通字段的访问方式: class Fansik: def __in ...

  9. 编译原理课后习题答案令A,B和C是任意正规式,证明以下关系成立(A|B)*=(A*B*)*=(A*|B*)*

    题目: 令A.B和C是任意正规式,证明以下关系成立: A∣A=A (A*)*= A*         A*=ε∣A A*        (AB)*A=A(BA)*        (A∣B)*=(A*B ...

  10. python16_day01【介绍、基本语法、流程控制】

    一.day01 1.二进制运算 60 & 13 =12 60 | 13 =61 60 ^ 13 =49 60<<2 =240 60>>2 =15 2.逻辑运算符 and ...