gpt4 book ai didi

javascript - 使用正则表达式,我如何多次匹配 XML 标记?

转载 作者:行者123 更新时间:2023-12-01 08:07:17 25 4
gpt4 key购买 nike

首先,在您说什么之前,我必须这样做,因为 RSS 格式不正确,但我无法自行更正它。因此,当我尝试使用 RSS 和 XML 解析器时,它们都失败了,我只能访问前端。但是,我非常接近,但我不明白为什么这不匹配。

提要(它是一个 1 行字符串): http://pastebin.com/5dJhXCvf

第一个例子:

<title>(.+)</title>

我认为这对我的测试非常有效:

<title>&quot;cterrorism task force&quot; location:oregon - Google News</title>

但问题是它会匹配所有内容,例如:

<title>&quot;cterrorism task force&quot; location:oregon - Google News</title><title>&quot;cterrorism task force&quot; location:oregon - Google News</title>

等于我的数组中来自 exec()match() 的 1 个结果项

所以我尝试了:

<title>([\w\d\s\=\%\_\`\~\+\!\@\#\$\%\^\&\*\(\)\:\'\"\[\]\{\}\|\,\.\/]+)</title>

但这没有任何返回......有什么想法吗?

最佳答案

尝试非贪婪版本<title>(.+?)<\/title> . Here你可以在线测试这些东西。

关于javascript - 使用正则表达式,我如何多次匹配 XML 标记?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4341421/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com