转一篇关于正则表达式的!

http://www.cnblogs.com/zhzkl/archive/2006/10/01/519868.html

自己写的正则表达式特殊字符转义函数
        private string TranslateRegexString(string str)
        {
            string[] reserveChars = new string[] {"\\", ".", "$", "^", "[", "(", ")", "]", "{", "}", "*", "+", "?" };
            string[] replaceChars = new string[] {"\\\\", @"\.", @"\$", @"\^", @"\[", @"\(", @"\)", @"\]", @"\{", @"\}", @"\*", @"\+", @"\?" };
            string reStr = str;
            for (int i = 0; i < reserveChars.Length; i++)
                reStr = reStr.Replace(reserveChars[i], replaceChars[i]);
            return reStr;
        }
posted @ 2007-12-28 18:21  moonz-wu  阅读(198)  评论(0编辑  收藏  举报