正则表达式在 .NET 中返回转义匹配 - 为什么?

发布于 2024-11-17 02:29:11 字数 494 浏览 1 评论 0原文

正如您在屏幕截图中看到的,capture 捕获了正确的值 Boton \"Reservar\",但该属性似乎不可用。 Value 返回该值但转义,这不是我需要的。这是 .NET 的正常行为吗?通常情况下 Value 显示与对象字符串相同的值,但这次它被转义了。

此外,正如您在立即窗口中看到的那样,capture.ToString() 甚至 group 都会显示转义的值。

更糟糕的是,Value 用引号括起来,这不是正则表达式应该匹配的内容。

我已经尝试将 capture 转换为 Group 并再次调用 capture.Captures 以查看真正的匹配是否隐藏在更深的组中,但事实并非如此。

有什么想法吗?

在此处输入图像描述

As you can see in the screenshort, capture captures the right value Boton \"Reservar\", but that property doesn't seem to be available. Value returns that value but escaped, that's not what I need. Is this the normal behavior with .NET? It's usually the case that Value shows the same value as the object string, but this time it's escaped.

Also, as you can see in the Immediate Window, capture.ToString() and even group shows the value escaped.

Worse yet, Value is wrapped in quotes, which is not what the regex is supposed to match.

I already tried casting capture to Group and calling capture.Captures again to see if the real match is hidden in deeper groups but it isn't.

Any ideas?

enter image description here

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

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

发布评论

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

评论(1

塔塔猫 2024-11-24 02:29:11

内存中的字符串是正确的 - 它只是它在立即/监视/本地窗口中的表示被转义。我不知道为什么 Visual Studio 的人决定这样做,但一种可能的解释是您可以按原样复制该字符串并粘贴到您的代码中:

var match = "Botón \\\"Reservar\\\"";

并且它将具有捕获的实际值。如果单击“Value”属性值旁边的放大镜,您将看到没有转义的字符串。

The string in memory is correct - it's just its representation in the immediate / watch / locals window which is escaped. I don't know why the people from Visual Studio decided to do that, but one possible explanation is that you can copy that string as is and paste in your code:

var match = "Botón \\\"Reservar\\\"";

And it will have the actual value of the capture. If you click on the magnifying glass next to the value of the "Value" property you'll see the string without the escaping.

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