/****************************************************************************** * This program masks all but the last four digits if a credit card number. * * Copyright © 2021 Richard Lesh. All rights reserved. *****************************************************************************/ #undef NDEBUG #include "Utils.hpp" #include #include #include #include using namespace Utils; using namespace std; static const vector TEST_CASES = {"1234 5678 9012 3456", "4893 8573 0203 1929", "6992 2839 4929 3902"}; string mask_credit_card(string card_number) noexcept { return std::regex_replace(card_number, regex("\\d{4,4} "), "XXXX "); } int main(int argc, char **argv) { for (auto s : TEST_CASES) { cout << mask_credit_card(s) << endl; } return 0; }