正则表达式在 .NET 中返回转义匹配 - 为什么?
正如您在屏幕截图中看到的,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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
内存中的字符串是正确的 - 它只是它在立即/监视/本地窗口中的表示被转义。我不知道为什么 Visual Studio 的人决定这样做,但一种可能的解释是您可以按原样复制该字符串并粘贴到您的代码中:
并且它将具有捕获的实际值。如果单击“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:
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.