此方法用于在将字符串与正则表达式进行匹配时检索匹配项。
string.match( param )
param - 正则表达式对象。
如果正则表达式不包括g标志,它将返回与regexp.exec(String)相同的输出。
如果正则表达式包含g标志,该方法返回一个包含所有匹配项的Array。
<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>
运行上面代码输出
链接:https://www.learnfk.comhttps://www.learnfk.com/javascript/string-match.html
来源:LearnFk无涯教程网
Chapter 3.4.5.1,Chapter 3.4.5.1,.1
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)