0
我有,我用它來驗證電子郵件正則表達式,並在JavaScript它看起來像這樣:正則表達式的作品在Javascript中而不是在C#
function CheckIfValidEmail(TheEmail) {
return /^([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x22([^\x0d\x22\x5c\x80-\xff]|\x5c[\x00-\x7f])*\x22)(\x2e([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x22([^\x0d\x22\x5c\x80-\xff]|\x5c[\x00-\x7f])*\x22))*\x40([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x5b([^\x0d\x5b-\x5d\x80-\xff]|\x5c[\x00-\x7f])*\x5d)(\x2e([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x5b([^\x0d\x5b-\x5d\x80-\xff]|\x5c[\x00-\x7f])*\x5d))*$/.test(TheEmail);
}
我沒有創建一個正則表達式,我在網上找到的。我想使用相同的正則表達式在我的C#代碼擴展方法是這樣的:
public static bool IsValidEmailAddress(this string TentativeEmailAddress)
{
string Pattern = "@/^([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x22([^\x0d\x22\x5c\x80-\xff]|\x5c[\x00-\x7f])*\x22)(\x2e([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x22([^\x0d\x22\x5c\x80-\xff]|\x5c[\x00-\x7f])*\x22))*\x40([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x5b([^\x0d\x5b-\x5d\x80-\xff]|\x5c[\x00-\x7f])*\x5d)(\x2e([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x5b([^\x0d\x5b-\x5d\x80-\xff]|\x5c[\x00-\x7f])*\x5d))*$/";
Regex regex = new Regex(Pattern);
return regex.IsMatch(TentativeEmailAddress.ToLower());
}
基本上,我複製並粘貼在C#代碼中的正則表達式期待它的工作,而是我得到一個錯誤,指出消息parsing 'the regex' - Too many)'s.
我需要更改哪些內容才能完成此項工作?
謝謝。
聖潔的甜心主。讓我建議你嘗試這樣的:http://composableregex.apphb.com/來幫助你打破這種事情。完全披露,這是我寫的一個網站,用於構建可組合的正則表達式並幫助管理它。 – devshorts
我知道我需要一副新的眼鏡,正則表達式打破了我的;-) –