asp.net - 正则表达式中的 "(?i)"是什么意思?

标签 asp.net regex

正则表达式模式 (?i)(?<=<data name=")\w+(?=")可以捕获

测试
<data name="test" xml:space="preserve">
    <value>123</value>
</data>

但是“(?i)”在正则表达式中是什么意思?

最佳答案

这是一种指定匹配不区分大小写的方式。

这是关于 Regex options 的 MSDN 页面:

By applying inline options in a regular expression pattern with the syntax (?imnsx-imnsx). The option applies to the pattern from the point that the option is defined to either the end of the pattern or to the point at which the option is undefined by another inline option.

但实际上,看起来您正在处理 XML,在这种情况下,您实际上应该使用 XML 解析器,而不是正则表达式。框架中内置了一些用于处理 XML 的类,这些类正确地遵守了 XML 的所有规则。将 XML 视为“只是一个字符串”往往会导致脆弱的解决方案。

关于asp.net - 正则表达式中的 "(?i)"是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17399857/

相关文章:

javascript - 如何使 Javascript 正则表达式仅在两个字符彼此相邻时匹配?

asp.net - 在asp.net c#中使用 session 进行用户身份验证

asp.net - 如何在asp.net中安排批处理进程

excel - Excel VBA 正则表达式模式中的定界符,过滤某些内容但不过滤其他内容

regex - 匹配括号之间的语法高亮

regex - 查找重复标记的子字符串

c# - 如何正确重试 HttpRequestMessage?

asp.net - Elmah 的动态电子邮件主题?

c# - 带音乐的幻灯片放映 像 Asp.net 一样控制相册

c# - 使用通配符比较两个字符串