$re = '/^
(?: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})
$/mix';
$str = '#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
';
preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);
// Print the entire match result
var_dump($matches);
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 PHP, please visit: http://php.net/manual/en/ref.pcre.php