用C Regex類實現的一些常規輸入判斷

2021-05-21 14:57:54 字數 3589 閱讀 2471

using system;

using system.text.regularexpression_rs;

namespace metarcommonsupport

return metarnetregex.instance;

}private metarnetregex()

///

/// 判斷輸入的字串只包含漢字

///

///

///

public static bool ischinesech(string input)

///

/// 匹配3位或4位區號的**號碼,其中區號可以用小括號括起來,

/// 也可以不用,區號與本地號間可以用連字型大小或空格間隔,

/// 也可以沒有間隔

/// /(0/d/)[- ]?/d|0/d[- ]?/d|/(0/d/)[- ]?/d|0/d[- ]?/d

///

///

///

public static bool isphone(string input)

//)[- ]?//d$|^0//d[- ]?//d$|^//(0//d//)[- ]?//d$|^0//d[- ]?//d$";

regex regex = new regex(pattern);

return regex.ismatch(input);

}///

/// 判斷輸入的字串是否是乙個合法的手機號

///

///

///

public static bool ismobilephone(string input)

$");

return regex.ismatch(input);

}///

/// 判斷輸入的字串只包含數字

/// 可以匹配整數和浮點數

/// ^-?/d+$|^(-?/d+)(/./d+)?$

///

///

///

public static bool isnumber(string input)

///

/// 匹配非負整數

//////

///

///

public static bool isnotnagtive(string input)

///

/// 匹配正整數

///

///

///

public static bool isuint(string input)

///

/// 判斷輸入的字串字包含英文本母

///

///

///

public static bool isenglisch(string input)

///

/// 判斷輸入的字串是否是乙個合法的email位址

///

///

///

public static bool isemail(string input)

/.[0-9]/.[0-9]/.)|(([/w-]+/.)+))([a-za-z]|[0-9])(/]?)$";

regex regex = new regex(pattern);

return regex.ismatch(input);

}///

/// 判斷輸入的字串是否只包含數字和英文本母

///

///

///

public static bool isnumandench(string input)

///

/// 判斷輸入的字串是否是乙個超連結

///

///

///

public static bool isurl(string input)

///

/// 判斷輸入的字串是否是表示乙個ip位址

///

/// 被比較的字串

/// 是ip位址則為true

public static bool isipv4(string input)

}return true;

}///

/// 計算字串的字元長度,乙個漢字字元將被計算為兩個字元

///

/// 需要計算的字串

/// 返回字串的長度

public static int getcount(string input)

///

/// 呼叫regex中ismatch函式實現一般的正規表示式匹配

///

/// 要匹配的正規表示式模式。

/// 要搜尋匹配項的字串

/// 如果正規表示式找到匹配項,則為 true;否則,為 false。

public static bool ismatch(string pattern, string input)

///

/// 從輸入字串中的第乙個字元開始,用替換字串替換指定的正規表示式模式的所有匹配項。

///

/// 模式字串

/// 輸入字串

/// 用於替換的字串

/// 返回被替換後的結果

public static string replace(string pattern, string input, string replacement)

///

/// 在由正規表示式模式定義的位置拆分輸入字串。

///

/// 模式字串

/// 輸入字串

///

public static string split(string pattern, string input)

///

/// 判斷輸入的字串是否是合法的ipv6 位址

///

///

///

public static bool isipv6(string input)

int count = metarnetregex.getstringcount(input,"::");

if(count>1)

else if(count == 0)

:)[/da-f]$";

regex regex = new regex(pattern);

return regex.ismatch(input);

}else

:)::([/da-f]:)[/da-f]$";

regex regex1 = new regex(pattern);

return regex1.ismatch(input);}}

///

/// 判斷字串compare 在 input字串中出現的次數

///

/// 源字串

/// 用於比較的字串

/// 字串compare 在 input字串中出現的次數

private static int getstringcount(string input, string compare)

else}}

}

git 一些常規指令

1.git初始化,新建乙個本地庫 git init 2.git help 檢視所有指令git help 3.git clone url 轉殖遠端庫 git clone 4.git remote add origin url 新增遠端庫 git remote add origin 5.git remo...

linux gdb的一些常規使用 cmake

原文 1.cmake支援gdb的實現,首先在cmakelists.txt下加入 set cmake build type debug 在下面加入 set cmake cxx flags debug env o0 wall g ggdb set cmake cxx flags release env ...

一些常規面試題

說說mysql主從同步怎麼做的吧?master提交完事務後,寫入binlog sl e連線到master,獲取binlog master建立dump執行緒,推送binglog到sl e sl e啟動乙個io執行緒讀取同步過來的master的binlog,記錄到relay log中繼日誌中 sl e再...