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

 
 
RegExp.$n
参数

 
 
RegExp

始终为全局 RegExp 对象。

n

1 至 9 之间的任意整数。

备注

 
 

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

示例

 
 

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

 
var newLine = "<br />";

var re = /(\w+)@(\w+)\.(\w+)/g
var src = "Please send mail to george@contoso.com and someone@example.com. Thanks!" var result;
var s = ""; // Get the first match.
result = re.exec(src); while (result != null) {
// Show the entire match.
s += newLine; // Show the match and submatches from the RegExp global object.
s += "RegExp.lastMatch: " + RegExp.lastMatch + newLine;
s += "RegExp.$1: " + RegExp.$1 + newLine;
s += "RegExp.$2: " + RegExp.$2 + newLine;
s += "RegExp.$3: " + RegExp.$3 + newLine; // Show the match and submatches from the array that is returned
// by the exec method.
for (var index = 0; index < result.length; index++) {
s += index + ": ";
s += result[index];
s += newLine;
} // Get the next match.
result = re.exec(src);
}
document.write(s); // Output:
// RegExp.lastMatch: george@contoso.com
// RegExp.$1: george
// RegExp.$2: contoso
// RegExp.$3: com
// 0: george@contoso.com
// 1: george
// 2: contoso
// 3: com // RegExp.lastMatch: someone@example.com
// RegExp.$1: someone
// RegExp.$2: example
// RegExp.$3: com
// 0: someone@example.com
// 1: someone
// 2: example
// 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. Share and NTFS Permission

    NTFS Permissions Share Permissions Share and NTFS Permission Similarities 共享权限和NTFS权限的相似性 Modifying ...

  2. C++ 动态内存 栈堆

    C++ 动态内存_w3cschool https://www.w3cschool.cn/cpp/cpp-dynamic-memory.html

  3. ios cocos2d 使用 sneakyInput 插件

    昨晚看了篇使用sneakyInput插件实现模拟手柄的代码,不过我加上后出现了很多问题.最后只看如何实现,没有自己动手去操作.今天终于吧问题都解决了.记录下来.也供别人参考. 首先要先加入libz.d ...

  4. Java 集合框架工具类

    Collections Arrays Collections 集合框架的工具类, 里面的方法都是静态的, 可以直接使用类名调用 常用方法 1. sort(List<T> list); // ...

  5. 详解JMeter函数和变量(转载)

    详解JMeter函数和变量(1) JMeter函数可以被认为是某种特殊的变量,它们可以被采样器或者其他测试元件所引用.函数调用的语法如下: ${__functionName(var1,var2,var ...

  6. Linux学习笔记(9)linux网络管理与配置之一——Linux基础网络命令与学习大纲(0)

    大纲目录 0.常用linux基础网络命令 1.配置主机名 2.配置网卡信息与IP地址 3.配置DNS客户端 4.配置名称解析顺序 5.配置路由与默认网关 6.双网卡绑定 [1] ping [2]net ...

  7. redis的图形化工具(四)

    1. 介绍 本篇会介绍几个关于redis的图形化的监控工具和管理工具. 2. redis-stat redis-stat提供终端和web端的监控页面,它安装和使用起来很简单. 安装只需要一条指令. $ ...

  8. C++匿名命名空间

    当定义一个命名空间时,可以忽略这个命名空间的名称:      namespce {          char c;          int i;          double d;      } ...

  9. [翻译]Feedback on the Go Challenge solutions

    第一次Go Challenge比赛,中国区只有3人参赛. 赛后收到邮件,是一个审阅者的反馈,“Feedback on the Go Challenge solutions”,摘录如下: 保持简单粗暴 ...

  10. cdojR - Japan

    地址:http://acm.uestc.edu.cn/#/contest/show/95 题目: R - Japan Time Limit: 3000/1000MS (Java/Others)     ...