惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
Last Week in AI
Last Week in AI
U
Unit 42
aimingoo的专栏
aimingoo的专栏
Engineering at Meta
Engineering at Meta
博客园 - 聂微东
小众软件
小众软件
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Recent Announcements
Recent Announcements
罗磊的独立博客
MongoDB | Blog
MongoDB | Blog
Stack Overflow Blog
Stack Overflow Blog
博客园_首页
M
MIT News - Artificial intelligence
博客园 - 司徒正美
T
The Blog of Author Tim Ferriss
D
DataBreaches.Net
IT之家
IT之家
C
Check Point Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
T
Tailwind CSS Blog
D
Docker
Microsoft Security Blog
Microsoft Security Blog
Google DeepMind News
Google DeepMind News

博客园 - gotolovo

导出csv 导出excel logmanager des 加密 解密 - gotolovo c# 发送邮件 工作流学习过程-事务 工作流学习过程-状态机 蛋疼的viewstate 工作流学习过程-持久化服务 工作流学习过程-使用关联 工作流学习过程-本地服务之事件处理 工作流学习过程-本地服务之调用方法 工作流学习过程-验证活动 工作流学习过程-自定义活动 工作流学习过程-开篇 基本的几个排序算法 关于sql中时间的格式转换 数据行变列 请编程遍历页面上所有TextBox控件并给它赋值为空
正则学习电话匹配
gotolovo · 2011-09-24 · via 博客园 - gotolovo
private static void Replace(string html)
{
if (html.IndexOf(',') > 0)
{
html = html.Substring(0, html.IndexOf(','));
}

html = Regex.Replace(html, @"\s|[a-z]|[\u4e00-\u9fa5]", string.Empty, RegexOptions.IgnoreCase);
//html = Regex.Replace(html, @"[a-z]", string.Empty, RegexOptions.IgnoreCase);
//html = Regex.Replace(html, @"[\u4e00-\u9fa5]", string.Empty, RegexOptions.IgnoreCase);
// 长度不足的直接返回
if (html.Length < 7)
{
// return html;
}
html = Regex.Replace(html, @"[–-\*]", "-");
html = Regex.Replace(html, "[(.)]", string.Empty);
html = Regex.Replace(html, "--", "-");
//html = Regex.Replace(html, ".", "");
//html = Regex.Replace(html, "–", "-");

if (Regex.IsMatch(html, @"^400"))
{
html = Regex.Replace(html, "-", "");
if (html.Length > 10)//有分机号
{
html = html.Insert(10, "-");
}
html += "特殊电话";
}
else if (Regex.IsMatch(html, @"^1[35]\d{9}$"))//正常手机
{
html = html + "正常手机";
}
else if (Regex.IsMatch(html, @"^1[35]\d{9}"))//不正常手机
{
html = Regex.Match(html, @"^1[35]\d{9}").Value + "不正常手机";
}
else if (Regex.IsMatch(html, @"^0\d{2,3}-*\d{7,8}$"))//正常电话无分机号
{
html = Regex.Replace(html,"-",string.Empty) + "正常电话";
}
else if (Regex.IsMatch(html, @"^0\d{2,3}-*\d{7,8}-*\d+$"))//正常电话有分机号
{
html += "正常电话有分机号";
}
else if(Regex.IsMatch(html, @"^0\d{2,3}-*\d{4,6}-*\d{2,4}$"))//正常电话无分机号被字符分隔
{
html = Regex.Replace(html, "-", string.Empty) + "正常电话无分机号被字符分隔";
}
else if (Regex.IsMatch(html, @"^(0\d{2,3}-*\d{4,6}-*\d{2,4})(-\d+$)"))//正常电话有分机号被字符分隔
{
Match match = Regex.Match(html, @"^(0\d{2,3}-*\d{4,6}-*\d{2,4})(-\d+$)");//正常电话有分机号被字符分隔
html = match.Groups[1].Value.Replace("-", string.Empty) +match.Groups[2].Value +"正常电话有分机号被字符分隔";
}
else
{
html = string.Empty;
}
Console.WriteLine(html);
//return html;
}


编辑器加载中...