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

 
 
  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. 创建存储过程修改role密码

    1 创建存储过程 DELIMITER | drop procedure if exists pro_update_role_pwd; CREATE PROCEDURE pro_update_role_ ...

  2. 让select下的option选中

    这里以默认选中当前月为例: HTML: 性别 <select name="sex" id="sex"> <option value=" ...

  3. jquery根据值设置radio和select选中状态

    1.radio选中: $("input[name=test][value=34]").attr("checked",true);//value=34的radio ...

  4. 【Linux command reference】

    ubuntu16.04安装中文输入法: https://blog.csdn.net/singleyellow/article/details/77448246 ubuntu16.04 用vi编辑代码, ...

  5. screenX clientX pageX区别

    screenX:鼠标位置相对于用户屏幕水平偏移量,而screenY也就是垂直方向的,此时的参照点也就是原点是屏幕的左上角. clientX:跟screenX相比就是将参照点改成了浏览器内容区域的左上角 ...

  6. django的项目创建简明流程

    个人理解,不妥之处请指出 创建项目:django-admin startproject user_sys 创建APP:python manage.py startapp auth 测试项目创建是否成功 ...

  7. CNN结构

    神经网络 卷积神经网络依旧是层级网络,只是层的功能和形式做了变化,可以说是传统神经网络的一个改进.多了许多传统神经网络没有的层次. 卷积神经网络的层级结构 数据输入层/Input Layer 卷积计算 ...

  8. node.js基本工作原理及流程

    概述 Node.js是什么 Node 是一个服务器端 JavaScript 解释器,用于方便地搭建响应速度快.易于扩展的网络应用.Node.js 使用事件驱动, 非阻塞I/O 模型而得以轻量和高效,非 ...

  9. Oracle Shared Pool 原理

    Oracle Shared Pool 原理 由于shared pool中最重要的是library cache,所以本文主要讲解Library cache的结构,library cache latch, ...

  10. 剑指offer(第2版)刷题 Python版汇总

    剑指offer面试题内容 第2章 面试需要的基础知识 面试题1:赋值运算符函数 面试题2:实现Singleton模式  解答 面试题3:数组中重复的数字 解答 面试题4:二维数组中的查找 解答 面试题 ...