JavaScript中String.match()方法的使用详解

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

JavaScript中String.match()方法的使用详解

  2020-05-13 我要评论

 此方法用于当匹配针对正则表达式的字符串来检索匹配。
语法

string.match( param )

下面是参数的详细信息:

  •     param : 正则表达式对象

返回值:

  •     如果正则表达式不包括g标志,返回的结果相同于regexp.exec(string)
  •     如果正则表达式包含g标志,则该方法返回一个包含所有匹配的数组

例子:

<html>
<head>
<title>JavaScript String match() Method</title>
</head>
<body>
<script type="text/javascript">
var str = "For more information, see Chapter 3.4.5.1";
var re = /(chapter \d+(\.\d)*)/i;
var found = str.match( re );

document.write(found ); 

</script>
</body>
</html>

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们