Can't match string using regular expression with "?"

c#, regex

Solution

Your pattern is good, all you need to add is: `(?i)` at the begining

or IgnoreCase in the regex options. `RegexOptions.IgnoreCase`

Note: since you don't need to capture "redit" or "ard", non capturing groups `(?:...)` are better:

(?i)C(?:redit)?C(?:ard)?N(?:um(?:ber)?)?

If you want to have more control with the case:

C(?i:redit)?C(?i:ard)?N(?i:um(?:ber)?)?

For more security you can add word boundaries at the begining and at the end of the pattern `\b`

Problem

I need to build regular expression to match following strings: - CCN - CreditCardNum - CreditCardNUmber - CCNumber etc. I built it as follows : `C(redit)?C(ard)?N(um|umber)?` It doesn't match "CreditCardNumber" string. I also tried : `C(redit)?C(ard)?N(:?um|umber)` without success

Original source