$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)中受支持。请参阅版本信息。
随机推荐
- 创建存储过程修改role密码
1 创建存储过程 DELIMITER | drop procedure if exists pro_update_role_pwd; CREATE PROCEDURE pro_update_role_ ...
- 让select下的option选中
这里以默认选中当前月为例: HTML: 性别 <select name="sex" id="sex"> <option value=" ...
- jquery根据值设置radio和select选中状态
1.radio选中: $("input[name=test][value=34]").attr("checked",true);//value=34的radio ...
- 【Linux command reference】
ubuntu16.04安装中文输入法: https://blog.csdn.net/singleyellow/article/details/77448246 ubuntu16.04 用vi编辑代码, ...
- screenX clientX pageX区别
screenX:鼠标位置相对于用户屏幕水平偏移量,而screenY也就是垂直方向的,此时的参照点也就是原点是屏幕的左上角. clientX:跟screenX相比就是将参照点改成了浏览器内容区域的左上角 ...
- django的项目创建简明流程
个人理解,不妥之处请指出 创建项目:django-admin startproject user_sys 创建APP:python manage.py startapp auth 测试项目创建是否成功 ...
- CNN结构
神经网络 卷积神经网络依旧是层级网络,只是层的功能和形式做了变化,可以说是传统神经网络的一个改进.多了许多传统神经网络没有的层次. 卷积神经网络的层级结构 数据输入层/Input Layer 卷积计算 ...
- node.js基本工作原理及流程
概述 Node.js是什么 Node 是一个服务器端 JavaScript 解释器,用于方便地搭建响应速度快.易于扩展的网络应用.Node.js 使用事件驱动, 非阻塞I/O 模型而得以轻量和高效,非 ...
- Oracle Shared Pool 原理
Oracle Shared Pool 原理 由于shared pool中最重要的是library cache,所以本文主要讲解Library cache的结构,library cache latch, ...
- 剑指offer(第2版)刷题 Python版汇总
剑指offer面试题内容 第2章 面试需要的基础知识 面试题1:赋值运算符函数 面试题2:实现Singleton模式 解答 面试题3:数组中重复的数字 解答 面试题4:二维数组中的查找 解答 面试题 ...