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

推荐订阅源

S
SegmentFault 最新的问题
Jina AI
Jina AI
罗磊的独立博客
V
Visual Studio Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
J
Java Code Geeks
U
Unit 42
Microsoft Azure Blog
Microsoft Azure Blog
B
Blog RSS Feed
爱范儿
爱范儿
酷 壳 – CoolShell
酷 壳 – CoolShell
Last Week in AI
Last Week in AI
T
The Blog of Author Tim Ferriss
腾讯CDC
Hugging Face - Blog
Hugging Face - Blog
T
Tailwind CSS Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
I
InfoQ
月光博客
月光博客
博客园_首页
Vercel News
Vercel News
P
Proofpoint News Feed
GbyAI
GbyAI
Y
Y Combinator Blog

博客园 - 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;
}


编辑器加载中...