I need to build regular expression to match following strings:
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With