正则表达式
1、至少有一个数字:([0-9]+)
2、表示至少有一个汉字:([^/]+)
3、截取字符串(截取内容中所有a标签中的链接) string[] link = Regex.Split(sArray[i], @"<a[^>]*href=(""(?<href>[^""]*)""|'(?<href>[^']*)'|(?<href>[^\s>]*))[^>]*>(?<text>.*?)</a>", RegexOptions.IgnoreCase | RegexOptions.Singleline);
4、//去掉多余空字符串
htmlBody = Regex.Replace(htmlBody, @"\s+", " ", RegexOptions.Multiline | RegexOptions.IgnoreCase);
htmlBody = Regex.Replace(htmlBody, @"\s*=\s*", "=", RegexOptions.Multiline | RegexOptions.IgnoreCase);
htmlBody = Regex.Replace(htmlBody, @"\s*<\s*", "<", RegexOptions.Multiline | RegexOptions.IgnoreCase);
htmlBody = Regex.Replace(htmlBody, @"\s*>\s*", ">", RegexOptions.Multiline | RegexOptions.IgnoreCase);
htmlBody = Regex.Replace(htmlBody, @"\s*/\s*", "/", RegexOptions.Multiline | RegexOptions.IgnoreCase);
5、//去掉背景、去掉颜色
htmlBody = Regex.Replace(htmlBody, @"(style\s*?=[\s\S]*?)(background\s*[:]\s*[\s\S]*?)([;""]+?)", "$1", RegexOptions.Multiline | RegexOptions.IgnoreCase);
htmlBody = Regex.Replace(htmlBody, @"(style\s*?=[\s\S]*?)(background\[\s\S]*?)([;""]+?)", "$1", RegexOptions.Multiline | RegexOptions.IgnoreCase);
htmlBody = Regex.Replace(htmlBody, "(style\\s*?=[\\s\\S]*?)(background-color[\\s\\S]*?)([;\"]+?)", "$1", RegexOptions.Multiline | RegexOptions.IgnoreCase);
htmlBody = Regex.Replace(htmlBody, "(style\\s*?=[\\s\\S]*?)(color*?)([;\"]+?)", "$1", RegexOptions.Multiline | RegexOptions.IgnoreCase);
6、截取字符串(截取内容中所有img标签中的链接) MatchCollection mc2 = Regex.Matches(htmlBody, @"<img\b[^<>]*?\bsrc[\s\t\r\n]*=[\s\t\r\n]*[""']?[\s\t\r\n]*(?<imgUrl>[^\s\t\r\n""'<>]*)[^<>]*?/?[\s\t\r\n]*>", RegexOptions.Multiline | RegexOptions.IgnoreCase);
7.js验证密码必须包含大小写字母,特殊符号,数字的正则8~~16位:
var v=$("#text").val();
reg=/^(?![0-9]+$)(?![a-z]+$)(?![A-Z]+$)(?!([^(0-9a-zA-Z)])+$).{6,}$/;
alert(reg.test(v));
8、Regex reg = new Regex(@"<img.*?src=""(?<src>[^""]*)""[^>]*>", RegexOptions.IgnoreCase);//根据正则匹配图片
9、此正则表达式可用于验证强密码。它需要至少 1 个小写字母、1 个大写字母和 1 个数字。它还允许使用一些特殊字符。长度应大于 8 个字符。字符的顺序并不重要。
public const string PasswordRegex = "(?=^.{8,}$)(?=.*\\d)(?=.*[a-z])(?=.*[A-Z])(?!.*\\s)[0-9a-zA-Z!@#$%^&*()]*$";