檢查郵箱合法性

2021-07-09 02:00:18 字數 784 閱讀 4944

1、標準的c和c++都不支援正規表示式,但有一些函式庫可以輔助c/c++程式設計師完成這一功能,其中最著名的當數philip hazel的perl-compatible regular expression庫,許多linux發行版本都帶有這個函式庫。

2、c/c++ 中使用正規表示式一般分為三步:

1)編譯正規表示式 regcomp()

int regcomp (regex_t *compiled, const char *pattern, int cflags)

這個函式把指定的正規表示式pattern編譯成一種特定的資料格式compiled,這樣可以使匹配更有效。函式regexec 會使用這個資料在目標文字串中進行模式匹配。執行成功返回0。

2)匹配正規表示式 regexec()

int regexec (regex_t *compiled, char *string, size_t nmatch, regmatch_t matchptr , int eflags)

當編譯好正規表示式後,就可以用regexec 匹配我們的目標文字串了,如果在編譯正規表示式的時候沒有指定cflags的引數為reg_newline,則預設情況下是忽略換行符的,也就是把整個文字串當作乙個字串處理。執行成功返回0。

3)釋放正規表示式 regfree()

void regfree (regex_t *compiled)

當使用完編譯好的正規表示式後,或者要重新編譯其他正規表示式的時候,可以用這個函式清空compiled指向的regex_t結構體的內容。請注意,如果是重新編譯的話,一定要先清空regex_t結構體。

檢查 URL 合法性

方法一 自己總結,親測可用 public static boolean checkurl string url 0 9 1 9 0 9 1 9 25 0 5 2 0 4 0 9 0 1 0 9 1 9 0 9 1 9 0 25 0 5 2 0 4 0 9 0 1 0 9 1 9 0 9 1 9 0 ...

JAVA日期合法性檢查

日期檢查 param pinput 要檢查的字串 return boolean 檢查結果 public static boolean isdate string pinput string regex d 02468 048 13579 26 0?1357 8 1 02 0?1 9 1 2 0 9 ...

asp檢測郵箱的合法性

dim email email request.form email if isvalidemail email then if request action 退訂 then response.redirect del email.asp?email email else response.redi...