.NET正则表达式中的i是什么意思?

时间:2021-12-22 03:58:16

In our code there is a regular expression of the following form:

在我们的守则中,有以下形式的正则表达式:

string regex = @"(?i)foo=(BAR?-[A-Z]+(33|34)?)";

What does the "(?i)" at the beginning of the regex match/do? I've looked through the .NET regex documentation and can't seem to figure out what (?i) would mean. Thanks!

regex匹配/开始时的“(?i)”是什么?我查阅了。net regex文档,似乎不知道(? ? I)是什么意思。谢谢!

5 个解决方案

#1


12  

(?i) activates case-insensitive matching.

(?我)激活不区分大小写的匹配。

Reference: MSDN, Regular Expression Options (highlighting by me):

参考:MSDN,正则表达式选项(由我高亮显示):

You can specify options for regular expressions in one of three ways:

您可以通过以下三种方式之一指定正则表达式的选项:

  • In the options parameter of a System.Text.RegularExpressions.Regex class constructor or static (Shared in Visual Basic) pattern-matching method, such as Regex.Regex(String, RegexOptions) or Regex.Match(String, String, RegexOptions). [...]

    在System.Text.RegularExpressions的options参数中。Regex类构造函数或静态(在Visual Basic*享)模式匹配方法,如Regex。正则表达式(字符串,RegexOptions)或正则表达式。匹配(字符串,字符串,RegexOptions)。[…]

  • 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. [...]

    通过使用语法(?imnsx-imnsx)在正则表达式模式中应用内联选项。该选项适用于模式,从该选项被定义为模式的末尾,到该选项未被另一个内联选项定义的点。[…]

  • By applying inline options in a particular grouping construct in a regular expression pattern with the syntax (?imnsx-imnsx:subexpression). [...]

    通过使用语法(?imnsx-imnsx:subexpression)在正则表达式模式中的特定分组构造中应用内联选项。[…]

#2


4  

(?i) means: Ignore case option enabled. It's equivalent to call Regex.Matches with 3rd param RegexOptions.IgnoreCase

(?i)表示:忽略已启用的case选项。它等价于调用Regex。匹配第三个参数RegexOptions.IgnoreCase

#3


3  

It sets regex to ignore the case. In the future you can use Expresso to figure things like this out:.NET正则表达式中的i是什么意思?

它让regex忽略这个案例。将来你可以用Expresso来表达这样的事情:

#4


1  

(?i) turns on case insensitivity. So its a case insensitive match.

(i)打开机箱不敏感。所以它是不区分大小写的匹配。

#5


1  

Turns on ignore case within the enclosing group

在封闭组中打开忽略大小写

#1


12  

(?i) activates case-insensitive matching.

(?我)激活不区分大小写的匹配。

Reference: MSDN, Regular Expression Options (highlighting by me):

参考:MSDN,正则表达式选项(由我高亮显示):

You can specify options for regular expressions in one of three ways:

您可以通过以下三种方式之一指定正则表达式的选项:

  • In the options parameter of a System.Text.RegularExpressions.Regex class constructor or static (Shared in Visual Basic) pattern-matching method, such as Regex.Regex(String, RegexOptions) or Regex.Match(String, String, RegexOptions). [...]

    在System.Text.RegularExpressions的options参数中。Regex类构造函数或静态(在Visual Basic*享)模式匹配方法,如Regex。正则表达式(字符串,RegexOptions)或正则表达式。匹配(字符串,字符串,RegexOptions)。[…]

  • 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. [...]

    通过使用语法(?imnsx-imnsx)在正则表达式模式中应用内联选项。该选项适用于模式,从该选项被定义为模式的末尾,到该选项未被另一个内联选项定义的点。[…]

  • By applying inline options in a particular grouping construct in a regular expression pattern with the syntax (?imnsx-imnsx:subexpression). [...]

    通过使用语法(?imnsx-imnsx:subexpression)在正则表达式模式中的特定分组构造中应用内联选项。[…]

#2


4  

(?i) means: Ignore case option enabled. It's equivalent to call Regex.Matches with 3rd param RegexOptions.IgnoreCase

(?i)表示:忽略已启用的case选项。它等价于调用Regex。匹配第三个参数RegexOptions.IgnoreCase

#3


3  

It sets regex to ignore the case. In the future you can use Expresso to figure things like this out:.NET正则表达式中的i是什么意思?

它让regex忽略这个案例。将来你可以用Expresso来表达这样的事情:

#4


1  

(?i) turns on case insensitivity. So its a case insensitive match.

(i)打开机箱不敏感。所以它是不区分大小写的匹配。

#5


1  

Turns on ignore case within the enclosing group

在封闭组中打开忽略大小写