$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)中受支持。请参阅版本信息。
随机推荐
- Go & SQLite on Windows
一般golang使用的sqlite驱动包都是github.com/mattn/go-sqlite3,但是官方并没有直接支持windows平台的编译,因为windows平台编译默认需要gcc支持 其实解 ...
- Kubernetes资源创建yml语法
前言 在是用kubernetes中,我们对资源的创建大部分都是通过 1 kubelet create -f RESOURCE.yaml 刚开看的时候不免有一些迷茫,看不懂语法,不知道怎么写:今天本文就 ...
- SOE 中调用第三方dll
一.简介 在利用soe实现server的扩展的时候,有些时候,需要调用第三方的dll库.官网中给出了明确的说明,soe中是可以添加第三方的dll文件,但是一直没有测试.按照官方的步骤应该是一个非常的简 ...
- kubernetes,Docker网络相关资料链接
1.Why kubernetes not doesn't use libnetwork http://blog.kubernetes.io/2016/01/why-Kubernetes-doesnt- ...
- django博客项目1.环境搭建
安装 Python Windows 下安装 Python 非常简单,去 Python 官方网站找到 Python 3 的下载地址,根据你的系统选择 32 位或者 64 位的安装包,下载好后双击安装即可 ...
- 012-JDK可视化监控工具-jstack
一.概述 jstack是java虚拟机自带的一种堆栈跟踪工具.jstack用于打印出给定的java进程ID或core file或远程调试服务的Java堆栈信息,如果是在64位机器上,需要指定选项&qu ...
- tomcat 6 利用ExpiresFilter控制静态文件缓存
在tomcat7下面 利用ExpiresFilter来控制静态文件缓存很方便,按照tomcat官网手动配置即可: 但是tomcat6 里面并没有 org.apache.catalina.filters ...
- table实现 js数据访问 传递json数据用render_to_response
$(document).ready(function(){ $.ajax({ url:'/query/', dataType:'json', type:'GET', success:function( ...
- 数据库权限分配(远程共享数据库)(mysql)
1. 数据库远程权限 mysql -uroot -proot grant all privileges on formal.* to root@'192.168.3.40' identified by ...
- Redis整合Spring实现缓存
一.Redis介绍 什么是Redis? redis是一个key-value存储系统.和Memcached类似,它支持存储的value类型相对更多,包括string(字符串).list(链表).set( ...