我有一个正则表达式来查找如下正则表达式:
^[a-zA-Z]{2}[0-9]{2}\s?[a-zA-Z0-9]{4}\s?[0-9]{4}\s?[0-9]{3}([a-zA-Z0-9]\s?[a-zA-Z0-9]{0,4}\s?[a-zA-Z0-9]{0,4}\s?[a-zA-Z0-9]{0,4}\s?[a-zA-Z0-9]{0,3})?$
这会发现 iban 如下所示:
DE89 3704 0044 0532 0130 00 ss
AT61 1904 3002 3457 3201
FR14 2004 1010 0505 0001 3
DE89370400440532013000
AT611904300234573201
但我的 iban 号码是在句子中的:
This is a cusotmer iban DE89 3704 0044 0532 0130 00 from somewhere
所以它找不到 iban。我该如何修复它?
试试这个方法:
static void Main()
{
string input = "This is a customer IBAN DE89 3704 0044 0532 0130 00 from somewhere. Another IBAN: AT61 1904 3002 3457 3201.";
string pattern = @"[a-zA-Z]{2}[0-9]{2}\s?[a-zA-Z0-9]{4}\s?[0-9]{4}\s?[0-9]{3}([a-zA-Z0-9]\s?[a-zA-Z0-9]{0,4}\s?[a-zA-Z0-9]{0,4}\s?[a-zA-Z0-9]{0,4}\s?[a-zA-Z0-9]{0,3})?";
Regex regex = new Regex(pattern);
MatchCollection matches = regex.Matches(input);
foreach (Match match in matches)
{
Console.WriteLine(match.Value);
}
}