在线等——字符串中提取电话号码

消失的尘芥 2011-08-31 10:55:00
字符串为以下两种格式,要提取里面电话号码

1 "齐叶(13414566541),王紫(15987904234)" (要提取里面的电话号码(13414566541,15987904234))

2 "齐叶(13414566541),15987904234" (要提取里面的电话号码(13414566541,15987904234))


拜托了,前辈们
...全文
336 19 打赏 收藏 转发到动态 举报
写回复
用AI写文章
19 条回复
切换为时间正序
请发表友善的回复…
发表回复
krenyelang 2011-08-31
  • 打赏
  • 举报
回复
使用SubString()实现。
云寂@ 2011-08-31
  • 打赏
  • 举报
回复
楼上各种高手,学习了
HDNGO 2011-08-31
  • 打赏
  • 举报
回复
IList<string> resultList = new List<string>();
try {
Regex regexObj = new Regex(@"(?<!\d)(13[0-9]|15[0|3|6|7|8|9]|18[8|9])\d{8}(?!\d)", RegexOptions.Singleline | RegexOptions.IgnoreCase);
Match matchResult = regexObj.Match(subjectString);
while (matchResult.Success) {
resultList.Add(matchResult.Value);
matchResult = matchResult.NextMatch();
}
} catch (ArgumentException ex) {
// Syntax error in the regular expression
}

HDNGO 2011-08-31
  • 打赏
  • 举报
回复
(?<!\d)(13[0-9]|15[0|3|6|7|8|9]|18[8|9])\d{8}(?!\d)
kiss筱魔 2011-08-31
  • 打赏
  • 举报
回复
string str = "齐叶(13414566541),王紫(15987904234)";
Regex Expression = new Regex("\b([0-9]{7,8}|0[0-9]{10,11}|1[0-9]{10})\b");
MatchCollection match = Expression.Matches(str);
foreach (Match m in match)
{
Response.Write(m.Value + "<br/>");
}
huangwenquan123 2011-08-31
  • 打赏
  • 举报
回复
            List<string> list = new List<string> { "齐叶(13414566541),王紫(15987904234)", "齐叶(13414566541),15987904234" };
Regex reg = new Regex(@"1[35]\d{9}");
foreach (string s in list)
foreach (Match m in reg.Matches(s))
Console.WriteLine(m.Value);
huangwenquan123 2011-08-31
  • 打赏
  • 举报
回复
            List<string> list = new List<string> { "齐叶(13414566541),王紫(15987904234)", "齐叶(13414566541),15987904234" };
Regex reg = new Regex(@"(?:13|15)\d{9}");
foreach (string s in list)
foreach (Match m in reg.Matches(s))
Console.WriteLine(m.Value);
子夜__ 2011-08-31
  • 打赏
  • 举报
回复
 string str = "齐叶(13414566541),王紫(15987904234)";
Regex Expression = new Regex("13[0-9]{9}|15[0-9]{9}");
MatchCollection match = Expression.Matches(str);
foreach (Match m in match)
{
Response.Write(m.Value + "<br/>");
}
bdmh 2011-08-31
  • 打赏
  • 举报
回复
正则直接取11位数字
Cosmo 2011-08-31
  • 打赏
  • 举报
回复
[Quote=引用 18 楼 jag580617 的回复:]
string str = "齐叶(13414566541),王紫(15987904234)";
Regex Expression = new Regex("^([1][3,5,8]\d{9})$");
MatchCollection match = Expression.Matches(str);
foreach (Match m in match)
{
Respon……
[/Quote]
顶下
jag580617 2011-08-31
  • 打赏
  • 举报
回复
string str = "齐叶(13414566541),王紫(15987904234)";
Regex Expression = new Regex("^([1][3,5,8]\d{9})$");
MatchCollection match = Expression.Matches(str);
foreach (Match m in match)
{
Response.Write(m.Value + "<br/>");
}
萧炎 2011-08-31
  • 打赏
  • 举报
回复

string input="字符串";
string s=@"^(13[0-9]|15[0|3|6|7|8|9]|18[8|9])\d{8}$";
if (Regex.IsMatch(input, s))
{
MessageBox.Show("符合!");
}

萧炎 2011-08-31
  • 打赏
  • 举报
回复
@"^(13[0-9]|15[0|3|6|7|8|9]|18[8|9])\d{8}$";这个够全面了 LZ
萧炎 2011-08-31
  • 打赏
  • 举报
回复
LZ如果说是制定的字符串的话 用substring()方便些
如果多个字符串中的话 正则表达式最快捷最方便
z22708387 2011-08-31
  • 打赏
  • 举报
回复
string str = "齐叶(13414566541),王紫(15987904234)";
Regex Expression = new Regex("1[35]\d{9}");
MatchCollection match = Expression.Matches(str);
foreach (Match m in match)
{
Response.Write(m.Value + "<br/>");
}
yykxcsd 2011-08-31
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 wxr0323 的回复:]
C# code
string str = "齐叶(13414566541),王紫(15987904234)";
Regex Expression = new Regex("13[0-9]{9}|15[0-9]{9}");
MatchCollection match = Expression.Matches(str);
foreach (Ma……
[/Quote]

这个只提取13.15开头的吧
chen_ya_ping 2011-08-31
  • 打赏
  • 举报
回复
非数字,除逗号以外的全部去掉,然后按照逗号分隔 OK
humin332 2011-08-31
  • 打赏
  • 举报
回复
楼主 需要的数据 用foreache 遍历下 就可以出来了
搞一个循环 只要是 数字 就 提取 不是就过滤 就OK 了
pyez1158 2011-08-31
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 huangwenquan123 的回复:]
C# code
List<string> list = new List<string> { "齐叶(13414566541),王紫(15987904234)", "齐叶(13414566541),15987904234" };
Regex reg = new Regex(@"1[35]\d{9}");
foreach (string s in list)
foreach (Match m in reg.Matches(s))
Console.WriteLine(m.Value);
[/Quote]

62,047

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧