正则零宽断言 Regex.Replace(string,string,string)
一直对Regex.Replace(string,string,string)这个没仔细了解 今天终于明白了 Regex.Replace(string input,string pattern,string replacement) (1) input: http://www.xxx.com/news/5/ pattern:.*?xxx\.com/news/\d+/ replacement:news.aspx 结果news.aspx 因为input按照pattern匹配的结果为 http://www.xxx.com/news/5/ ,然后我们用news.aspx替换 最终结果就是news.aspx (2) input: abcedft http://www.xxx.com/news/5/6/7YYYYY pattern: http://(.*/?)\.*xxx.com/news/(\d+/)*(\d+)/ * replacement: /news.aspx 结果为 abcedft/news.aspxYYYYY 因为input 中匹配的为 http://www.xxx.com/news/5/6/7 (3) input:http://www.xxx.com/news/5/ pattern:http://(.*?)\.xxx.com/news/(\d+)/ replacement:news