using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"^
(?:4[0-9]{12}(?:[0-9]{3})?
|
5[1-5][0-9]{14}
|
6(?:011|5[0-9][0-9])[0-9]{12}
|
3[47][0-9]{13}
|
3(?:0[0-5]|[68][0-9])[0-9]{11}
|
(?:2100|2131|1800|35\d{3})\d{11})
$";
string input = @"#American Express
370517943574132
372714451742486
370010255141385
341263547614307
343874494387669
#VISA
4024007125780444
4439944519233615
4658355677043536
4532926168018906
4532249806735728
#MasterCard
5524097521691644
5367170623993901
5553103980950937
5549194987582424
5141794881796756
#JCB 15 digits
180078244412845
210013400722277
210082510016250
180056142071970
210043823226606
#JCB
3158822586903214
3088687202983378
3158899851849561
3096803356450490
3337852908456769
#Dinners Club
30193567772121
30131361923813
30198560976769
30260244203356
36297440059376
";
RegexOptions options = RegexOptions.Multiline | RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace;
foreach (Match m in Regex.Matches(input, pattern, options))
{
Console.WriteLine("'{0}' found at index {1}.", m.Value, m.Index);
}
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for C#, please visit: https://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex(v=vs.110).aspx