非捕获之后是不是就不能运用捕获的内容了?麻烦解释下加粗的字
来源:3-26 分组和引用
为你浅笑
2019-07-06 15:09:57
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>正则</title>
</head>
<script type="text/javascript">
var str="ab cd ab";
var pattern=/(ab) cd \1/;
//如何才能让其只输出“ab cd ab” 为什么直接写成这样不行var pattern=/(?:ab) cd \1/;
document.write(pattern.exec(str)+"<br/>");
</script>
<body>
</body>
</html>
1回答
同学你好,
1、非捕获之后就不能运用捕获的内容了
2、只输出“ab cd ab”,可以这样写:
3、同学这样写是不对的,
\1代表的是第一个分组,而现在前面已经不能捕获了(因为使用了?:)所以这样写是不正确的,
祝学习愉快~
相似问题