作业帮 > 综合 > 作业

求一些常用的正则表达试.

来源:学生作业帮 编辑:搜搜做题作业网作业帮 分类:综合作业 时间:2024/07/03 07:57:19
求一些常用的正则表达试.
求一些常用的正则表达试.
常用的正则表达式
代码作用Regex r = new Regex("..");查找是否包含图片Regex rt = new Regex(@"script|iframe|\'|;| ",RegexOptions.IgnoreCase);查找是否包含去除脚本、框架、单引号通常用于验证URL传递参数,防sql住入Regex r = new Regex("||font-size:.
pt|font-size:.px|||
|
||",RegexOptions.IgnoreCase);
ListBox_37.DataTable.Rows[i]["title"] = r.Replace(ListBox_37.DataTable.Rows[i]["title"].ToString().Replace("
"," ").ToLower(),"");查找是否包含字体样式标签
用于去除字段内的字体样式Regex rTel = new Regex("^[0-9-]{8,8}$|^[0-9-]{11,12}$");
Boolean ismatch = rTel.IsMatch(p_phone.Value);验证输入
用于验证电话号码RegexrEmail=newRegex("^\\w+((-\\w+)|(\\.\\w+))*\\@[A-Za-z0-9]+
((\\.|-)[A-Za-z0-9]+)*\\.[A-Za-z0-9]+$");验证输入
用于验证邮箱格式private string RemoveHtml(string strHtml)
{
string strhtml = Regex.Replace(strHtml,"","");
strhtml = Regex.Replace(strhtml,"
","",RegexOptions.IgnoreCase);
return strhtml;
}清除带入参数中所有标签并返回private string StripHT(string strHtml)
{
Regex regex=new Regex("",RegexOptions.IgnoreCase);
String strOutput=regex.Replace
(strHtml.Replace("|","").Replace("
","|"),"").Replace(" "," ").Replace("“","“").Replace("”","”");
regex=new Regex("\\s",RegexOptions.IgnoreCase);
strOutput=regex.Replace(strOutput,"");
return "    "+strOutput.Replace("\"","").
Replace(""","").Replace("|","
");
}清除带入参数中的标签符号并返回Match mc = Regex.Match(dr["chcontent"].ToString(),"(?(.))",RegexOptions.IgnoreCase | RegexOptions.Compiled);
dr["href"]=mc.Groups["href"].Value;获取文章内容中的链接地址Regex r = new Regex(".xml.");查找是否包含xml
这个是我工作中摘取的一些内容.决非抄袭.