2014年4月5日 星期六
自動產生Regular Expressions
有時候常常不知道Regular Expressions 要怎麻寫才對
這邊有個網站,可以幫助產生正確的Regular Expressions
http://regexlib.com/Search.aspx?k=url&c=2&m=-1&ps=20
2011年9月23日 星期五
C# Regular Expression
今天在利用 Regular Expression 取得網頁中的某些資料時,發現因為 pattern 都是包在 ( ) 內,如果Html 的內容也有 ( ) 符號,好像會比對不到資料
查了一下,可以用 Regex.Escape("(") 來將符號轉成字串查詢
這樣就可以取到 (02) 了
string pattern = Regex.Escape("(") + "(.*?)" + Regex.Escape(")");
string input = "(02)1234567";
MatchCollection matches = Regex.Matches(input, pattern);
foreach (Match match in matches)
{
MessageBox.Show(match.Value);
}
訂閱:
文章 (Atom)