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

 
 
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. 对opencv.hpp头文件的认识

    OpenCV学习笔记(二):对opencv.hpp头文件的认识 - 安东的技术博客 - CSDN博客 https://blog.csdn.net/xidiancoder/article/details ...

  2. 模块化之SeaJS(一)

    模块化(之SeaJS) 刚接触的童鞋可能会有很多疑惑,比喻:什么是模块?模块的目的是干嘛呀?怎么样实现模块化呢? 不要急,博主正是带着这三个问题来写这篇文章的. 一,什么是模块化? 在前端开发领域,一 ...

  3. 用java求一个整数各位数字之和

    /* * 用java求一个整数各位数字之和 */ public class Test02 { public static void main(String[] args) { System.out.p ...

  4. 配置 Docker 镜像下载的本地 mirror 服务

    Docker registry 工具如今已经非常好的支持了 mirror 功能,使用它能够配置一个本地的 mirror 服务.将 pull 过的镜像 cache 在本地.这样其他主机再次 pull 的 ...

  5. 自定义ActionBar图标

    <style name="Theme.glTheme" parent="android:Theme.Holo"> <item name=&qu ...

  6. Windows 7 下 Node.js 连接 Oracle

    原创作者: sailtseng 1. 安装 Oracle 11g express  详见: <Windows 7 x64 安装 Oracle 11g Express> 2. 安装 Micr ...

  7. VIM 配置python

    Pre-install sudo yum install automake gcc gcc-c++ kernel-devel cmake sudo yum install python-devel p ...

  8. Hbase 学习笔记1----shell

    Hbase 是一个分布式的.面向列的开源数据库,其实现是建立在google 的bigTable 理论之上,并基于hadoop HDFS文件系统.     Hbase不同于一般的关系型数据库(RDBMS ...

  9. iOS学习之NSString

    一.不可变字符 NSString是不可变字符串,它产生的其他字符串方法都是生成一个新的字符串,而不会改变原来字符串. 1.创建方式 //1)字面量,它是常量字符串,存储常量区 NSString *st ...

  10. 开启无线WLAN方式

    1.以管理员身份运行命令提示符 因为下面的步骤必须在管理员权限下运行,因此我们从开始菜单找到"命令提示符",或直接键入cmd快速搜索,右键单击它,选择"以管理员身份运行& ...