2 VB 正则表达式问题

发布于 2024-10-05 04:41:50 字数 514 浏览 0 评论 0原文

我需要一些有关 VB RegEx 的帮助。

我有两个正则表达式,我需要做两件特定的事情。

RegEx 一 - 我不太确定如何执行此操作,但我需要在 Href 标记中获取所有内容。即

String = "<a href=""test.html"">"

我需要正则表达式返回... test.html

正则表达式二 - 我已经部分完成了这项工作。

我有这样的标签,

RegEx = "<div class=""top""(.*?)</div>"
String = "<div class=""top""><a><b><div class=""bottom""></div></b></a></div>"

我遇到的问题是这不返回任何内容,它应该返回带有“top”的所有内容,但它什么也不返回。

I need some help with a VB RegEx.

I've got two RegEx that I need to do two specific things.

RegEx one - I am not exactly sure how to do this, but I need to get everything within a Href tag. i.e.

String = "<a href=""test.html"">"

I need the RegEx to return .... test.html

RegEx Two - I have partly got this working.

I've got tags like

RegEx = "<div class=""top""(.*?)</div>"
String = "<div class=""top""><a><b><div class=""bottom""></div></b></a></div>"

The problem I have is this isnt returning anything, it should return everything withing "top", but it returns nothing.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

撑一把青伞 2024-10-12 04:41:50

这两种用例都不能用正则表达式很好地解决。

请改用 HTML 解析器,例如 HTML Agility Pack

Neither use-case can be solved well with regular expressions.

Use an HTML parser instead, e.g. the HTML Agility Pack.

君勿笑 2024-10-12 04:41:50

好吧,如果您的 html 不包含嵌套标签,您可以使用正则表达式完成第一部分(只要您可以控制搜索源代码,您就可以更加确定您的结果)。

\<a href=""([^""]+)\>

test.html 将在称为 $1非被动组中找到。

第二部分我担心你在那里嵌套了标签并且它在这方面失败了。正则表达式和 html 的问题在于,正则表达式无法深入研究嵌套允许但不是最佳实践的代码,这些代码可以按预期执行但格式不正确。

您可以发布第二个案例的一些搜索源以便我们查看吗?

Well, if your html doesn't contain nested tags you can do the first part with regex (as long as you can control your search source code, you can be much more certain of your results).

\<a href=""([^""]+)\>

the test.html will be found in the non-passive group referred to as $1.

The second part I'm concerned that you have nested tags in there and it's failing on that. The thing with regex and html is that regex can't delve well into the nested-allowable-but-not-best-practice code that can execute as expected but isn't well formed.

Can you post some search source for the second case so we can look?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文