有关正则表达式

来源:百度知道 编辑:UC知道 时间:2024/05/26 11:40:58
public static string InputText(string text)
{
text = text.Trim();
if (string.IsNullOrEmpty(text))
return string.Empty;

//if (text.Length > maxLength)
// text = text.Substring(0, maxLength);
text = Regex.Replace(text, "[\\s]{2,}", " "); //two or more spaces
text = Regex.Replace(text, "(<[b|B][r|R]/*>)+|(<[p|P](.|\\n)*?>)", "\n"); //<br>
text = Regex.Replace(text, "(\\s*&[n|N][b|B][s|S][p|P];\\s*)+", " "); // 
text = Regex.Replace(text, "<(.|\\n)*?>", string.Empty); //any other tags
text = text.Replace("'", "''");
return text;

}
这段代码什么意思啊?

text = Regex.Replace(text, "[\\s]{2,}", " "); //替换连续的多个空白字符为1个
text = Regex.Replace(text, "(<[b|B][r|R]/*>)+|(<[p|P](.|\\n)*?>)", "\n"); //移除空白的行,替换为\n
text = Regex.Replace(text, "(\\s*&[n|N][b|B][s|S][p|P];\\s*)+", " "); // 替换   为 空格
text = Regex.Replace(text, "<(.|\\n)*?>", string.Empty); // 移除其他HTML标签
text = text.Replace("'", "''"); // 单引号替换为双引号