C#正则表达式:忽略大小写...的格局? [英] C# RegEx: Ignore case... in pattern?
问题描述
我使用System.Text.RegularEx pressions.Regex.IsMatch(的TestString,regexPattern)做一些搜索字符串中。
I'm using System.Text.RegularExpressions.Regex.IsMatch(testString, regexPattern) to do some searches in strings.
有没有在regexPattern字符串的模式应该忽略的情况下,以指定的方式? (即不使用Regex.IsMatch(的TestString,regexPattern,RegexOptions.IgnoreCase))
Is there a way to specify in the regexPattern string that the pattern should ignore case? (I.e. without using Regex.IsMatch(testString, regexPattern, RegexOptions.IgnoreCase))
推荐答案
(我)
中的模式开始区分大小写的匹配,( ?-i)
重圆。即,
(?i)
within the pattern begins case-insensitive matching, (?-i)
ends it. That is,
(?i)foo(?-i)bar
匹配 foobar的
而不是 foobar的
。
编辑:我应该说( - 我?)
开始区分大小写的匹配 - 如果你只是希望整个模式区分不敏感,那么你并不需要结束的(我)
。
I should have said (?-i)
begins case-sensitive matching - if you just want the whole pattern to be case-insensitive then you don't need to "end" the (?i)
.
这篇关于C#正则表达式:忽略大小写...的格局?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!