【发布时间】:2019-12-19 00:21:31
【问题描述】:
我有一封标准电子邮件,我希望从中提取某些详细信息。
电子邮件中有这样的行:
<strong>Name:</strong> John Smith
所以为了模拟这个,我有以下 JavaScript:
var str = "<br><strong>Name:</strong> John Smith<br>";
var re = /\<strong>Name\s*:\<\/strong>\s*([^\<]*)/g
match = re.exec(str);
while (match != null) {
console.log(match[0]);
match = re.exec(str);
}
这只会得出一个结果,那就是:
<strong>Name:</strong> John Smith
我希望获得捕获组([^\<]*),在本例中为John Smith
我在这里错过了什么?
【问题讨论】:
-
我已经找到了“重复”的答案,这就是我从中获取测试脚本的地方
-
您需要在答案中进一步阅读,他说(隐藏在评论中!):“捕获组 n:匹配 [n]”。如果我在意识到必须有一个欺骗目标之前还没有回答这个问题,为了清楚起见,我会添加一条评论,恕我直言,这太隐蔽了。编码愉快!
标签: javascript regex