$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)中受支持。请参阅版本信息。
随机推荐
- Linux网络调试工具资料链接
Dropbox: https://huoding.com/2016/12/15/574 Tcpdump: http://roclinux.cn/?p=2474
- 假设做一个精美的Login界面(攻克了一EditText自带clear的功能,相似iphone的UITextField)
先上图: XML为: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" ...
- 004-shiro简介
一.什么是shiro shiro是apache的一个开源框架,是一个权限管理的框架,实现 用户认证.用户授权. spring中有spring security (原名Acegi),是一个权限框架,它和 ...
- Linux Shell编程第3章——正则表达式
目录 正则表达式基础 正则表达式的扩展 通配 grep命令 正则表达式基础 Linux Shell以字符串作为表达式向系统传达意思.元字符(Metacharacters)是用来阐述字符表达式意义的字符 ...
- .net:easyui-datagrid清空表中原有数据
$("#StudentTable").datagrid("loadData", { total: 0, rows: [] });
- 【工具】Notepad++ 上,代码格式化工具
一.概述 Windows 自带的记事本功能太过简单,因此我常常使用 Notepad++ 查看文本.Notepad++ 支持插件功能,最近需要使用 Notepad++ 查看 Html 代码,而这些代码多 ...
- PAT 天梯赛 L1-044. 稳赢 【循环】
题目链接 https://www.patest.cn/contests/gplt/L1-044 题意 根据对方给出剪刀石头步 给出对应的胜利出招,每K次 要有一个平局 思路 用一个循环,然后每K次 判 ...
- HDU - 6333 Problem B. Harvest of Apples (莫队+组合数学)
题意:计算C(n,0)到C(n,m)的和,T(T<=1e5)组数据. 分析:预处理出阶乘和其逆元.但如果每次O(m)累加,那么会超时. 定义 S(n, m) = sigma(C(n,m)).有公 ...
- C# Json格式
using LitJson; //自定义Json类 JsonDataResult jsondata = new JsonDataResult() { Success = false }; HttpCo ...
- 优秀 H5 案例收集 vol.3(不定期更新)
上期浏览:Vol.1 Vol.2 爱的不同定义,五笔连成爱http://news.163.com/special/fdh5_valentines/ 世界华语悬疑文学大赛—下一位悬疑大师,就是你!h ...