4文字以上のRegex Matchで問題が発生しました。私は4文字で試してみましたが、の種類が返されます。ただし、4文字以上の場合は、のような偽のが返されます。そこで何が起こったのか教えてください。Regex Match 4文字以上
public static string CardRegex = @"^(?:(?<VisaDebit>4744)| (?<Discover>6011)| (?<Amex>3[47]\d{2}))([ -]?)(?(DinersClub)(?:\d{6}\1\d{4})|(?(Amex)(?:\d{6}\1\d{5})|(?:\d{4}\1\d{4}\1\d{4})))$";
public static CreditCardTypeType? GetCardTypeFromNumber(string cardNum)
{
var cardTest = new Regex(CardRegex);
var gc = cardTest.Match(cardNum).Groups;
if (gc[CreditCardTypeType.VisaDebit.ToString()].Success)
return CreditCardTypeType.VisaDebit;
if (gc[CreditCardTypeType.Discover.ToString()].Success)
return CreditCardTypeType.Discover;
return null;
}
入力:4744721015347572
(?<VisaDebit>4744) ==> return VisaDebit
(?<VisaDebit>4744**7**) ==> return null
申し訳ありませんが、あなたの質問は不明です。あなたの唯一のサンプル文字列は '4744721015347572'で、あなたの正規表現は一致します(IgnoreWhitespaceフラグ付きでコンパイルされた場合)](http://regexstorm.net/tester?p=%5e%28%3f%3a%28%3f% 3cVisaDebit%3e4744%29%7c%0d%0a ++++++++%28%3f%3cDiscover%3e6011%29%7c%0d%0a ++++++++%28%3f%3cAmex%3e3%5b47%5d%5cd%7b2%7d%29%29% 28%5b + - %5d%3f%29%28%3f%28DinersClub%29%28%3f%3a%5cd%7b6%7d%5c1%5cd%7b4%7d%29%7c%28%3f%28Amex%29 %28%3f%3a%5cd%7b6%7d%5c1%5cd%7b5%7d%29%7c%28%3f%3a%5cd%7b4%7d%5c1%5cd%7b4%7d%5c1%5cd%7b4 * VisaDebit *グループでは「4744」と%7d%29%29%29%24&i = 4744721015347572&o = x)です。 –