Here's a simple LINQPad program that extracts all 16-digit numbers that starts with a 4 from the file:
void Main()
{
const string inputFileName = @"d:\temp\input.txt";
const string outputFileName = @"d:\temp\output.txt";
string input = File.ReadAllText(inputFileName);
var matches =
from Match ma in Regex.Matches(input, @"\d+")
let number = ma.Value
where number.Length == 16 && number.StartsWith("4")
select number;
var creditCardNumbers =
from match in matches
where IsCreditCardNumber(match)
select match;
File.WriteAllLines(outputFileName, creditCardNumbers);
}
public static bool IsCreditCardNumber(string number)
{
// validate luhn checksum here
return true;
}