Grynn
Grynn

Reputation: 1284

.Net regular expression: Inline case sensitivity not working

What am I doing wrong here? .Net supports the (?i:) construct for inline modification of case sensitivity ... but I can't get this line to work.

Console.WriteLine(Regex.Match("ab(?i:z)", "abZ").Success); //Returns false, 
                                           //though it should return true??

Upvotes: 1

Views: 149

Answers (3)

Heinzi
Heinzi

Reputation: 172448

The signature for Regex.Match is

public static Match Match(
    string input,
    string pattern
)

So, Regex.Match("abZ", "ab(?i:z)") will do what you want.

Upvotes: 3

spender
spender

Reputation: 120518

How about getting the parameters in the correct order?

Regex.Match("abZ", "ab(?i:z)").Success

Upvotes: 2

Guffa
Guffa

Reputation: 700730

The first parameter is the input, the second parameter is the pattern:

Regex.Match("abZ", "ab(?i:z)")

MSDN: Regex.Match(string, string)

Upvotes: 6

Related Questions