$1...$9 属性 (RegExp) (JavaScript)
返回在模式匹配期间找到的,所存储的最近的九个部分。 只读。
- 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)中受支持。请参阅版本信息。
随机推荐
- 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 ...
- jd算法大赛 一个user_id只需映射到一个sku_id, 但是一个sku_id能否映射到多个user_id
0-购买预测 w 任务目标 提交user_id-->sku_id (1->1,但反向呢?) 实际操作: 0- 行为表中的type值加权为一个购买意向值0(性别.年龄,不干扰/或加权) 品类 ...
- Struts 上传文件
1. 客户端注意事项 method="post" enctype="multipart/form-data" <input type="file ...
- 标准编译安装(cmake make)
为什么要编译安装?因为根据需求可以个性化定制功能. 关键是阅读cmakelist,看都有哪些依赖,都有哪些选项可用,哪些选项是自己可以配置的. 一般流程: mkdir build cd build c ...
- 缓存在中间件中的应用机制(Django)
缓存在中间件中的应用机制(Django) (右键图片:在新标签页中打开连接)
- 23种设计模式UML图
- Python 模块之 pyexcel_xls
一.适用场景 在很多数据统计或者数据分析的场景中,我们都会使用到excel: 在一些系统中我们也会使用excel作为数据导入和导出的方式,那么如何使用python加以辅助我们快速进行excel数据做更 ...
- Python基础-面向对象2
一.成员修饰符 共有成员 私有成员:创建方式在成员之前加两个下划线,私有成员无法直接访问,只能间接访问 子类不能继承父类的私有属相私有普通字段的访问方式: class Fansik: def __in ...
- 编译原理课后习题答案令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 ...
- python16_day01【介绍、基本语法、流程控制】
一.day01 1.二进制运算 60 & 13 =12 60 | 13 =61 60 ^ 13 =49 60<<2 =240 60>>2 =15 2.逻辑运算符 and ...