How to mask an email id in a string in C++ [on hold]

问题内容:

I have a string that looks like
The following email id(s) found non-existent: someone@microsoft-us.com to delete
I need to mask the email id with *s
the result should be
The following email id(s) found non-existent: ************************ to delete

How do I do this in C++ using regex?

I have tried

wstring m_piiRegexString = L"(\\w+)(\\.|_)?(\\w*)@(\\w+)(\\.(\\w+))+";//email
    const std::wregex PIIPattern(m_piiRegexString);
        std::string maskedString;
        std::regex_replace(std::back_inserter(maskedString), testString.begin(), testString.end(), PIIPattern, L"****");
        std::cout << maskedString;
  1. This does not work for some valid email ids like someone@micro-soft.co.jp
  2. Is there any way to replace the match with exact number of matching charactes with a mask (*)?

问题评论:

    
What have you tried so far?
    
I have tried std::regex_replace(std::back_inserter(maskedString), testString.begin(), testString.end(), PIIPattern, L”****”); with regex (\\w+)(\\.|_)?(\\w*)@(\\w+)(\\.(\\w+))+. It fails for some valid email id’s like someone@micr-osoft.com
– Madhusudan Narayan
7 hours ago

原文地址:

https://stackoverflow.com/questions/47747822/how-to-mask-an-email-id-in-a-string-in-c

Tags:, ,

添加评论

友情链接:蝴蝶教程