3 回答

TA貢獻1804條經驗 獲得超3個贊
在這種情況下,*.com 包括所有其他模式。您可以檢查電子郵件endwith .com是否足以滿足您的需求
List<string> emails = new List<string>
{
};
Regex regex = new Regex(@"(domain\.com)|(sub\.*\.com)");
emails= emails.Where(e => regex.IsMatch(e)).ToList();
如果要使用正則表達式檢查多個模式,可以使用 |
List<string> emails = new List<string>
{
};
Regex regex = new Regex(@"(domain.com)|(sub.*.com)");
emails= emails.Where(e => regex.IsMatch(e)).ToList();

TA貢獻2041條經驗 獲得超4個贊
您不需要正則表達式??梢杂?linq 完成:
string[] domains = { "*.sub.domain.com", "*.com", "*.domain.com", "sub.*.com" };
string email = "abc.sub.domain.com";
string user = "abc";
bool match = domains.Any(x => x.Replace("*", user) == email);

TA貢獻1810條經驗 獲得超4個贊
試試這個正則表達式:
^ [a-zA-Z0-9 _. + -] + @ (?: (?: [a-zA-Z0-9 -] +.)? [a-zA-Z] +.)? (provider1 | provider2 ). (domain1 | domain2) $
用這個例子嘗試了這個正則表達式:[email protected] - 是有效的
帶有子域的電子郵件的正則表達式:
^ [a-zA-Z0-9 _. + -] + @ (?: (?: [a-zA-Z0-9 -] +.)? [a-zA-Z] +.)? (sub1 | sub2 ). (provider1 | provider2). (domain1 | domain2) $
它適用于任何域和郵件服務提供商。我試過這個,它有效
- 3 回答
- 0 關注
- 214 瀏覽
添加回答
舉報