<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Document</title>
</head>
<body>
</body>
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<script>
let nr = "当一长段文字,我们需要正则匹配立面的412112199010112345证件号,并点击证件号跳转到新的页面时,需要将当前文本正则匹配到412112199010112346,并用a标签包裹起来。"
let pattern = RegExp(/(\d{17}[\d|X|x])/, 'g');
let res = nr.replace(pattern, '<a href="https://www.dtm.cc/?idcard=$1">$1</a>')
console.log(res)
</script>
</html>
发表评论 取消回复