Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# RegEx: Ignore case... in pattern?

Tags:

c#

regex

I'm using System.Text.RegularExpressions.Regex.IsMatch(testString, regexPattern) to do some searches in strings.

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))

like image 498
core Avatar asked Oct 18 '09 01:10

core


People also ask

What do you mean by C?

" " C is a computer programming language. That means that you can use C to create lists of instructions for a computer to follow. C is one of thousands of programming languages currently in use.

What is the full name of C?

In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr.


1 Answers

(?i) within the pattern begins case-insensitive matching, (?-i) ends it. That is,

(?i)foo(?-i)bar 

matches FOObar but not fooBAR.

EDIT: I should have said (?-i) starts case-sensitive matching - if you want the whole pattern to be case-insensitive then you don't need to "end" the (?i).

like image 98
stevemegson Avatar answered Sep 21 '22 21:09

stevemegson