我可以使用C#.net从文本中提取所有电话号码吗?
发布于 2011-03-25 15:16:16
正则表达式应该允许您这样做。
要对某些文本使用正则表达式,可以使用:
var exp = new Regex(
@"(\(?[0-9]{3}\)?)?\-?[0-9]{3}\-?[0-9]{4}", // North American example
RegexOptions.IgnoreCase);
var text = "My text including phone numbers";
MatchCollection matchList = exp.Matches(text);
// now iterate over matchList.Matches发布于 2011-03-25 15:19:41
·将北美电话号码与可选区号和要在电话号码中使用且无分机的可选字符进行匹配:
^(\(?[0-9]{3}\)?)?\-?[0-9]{3}\-?[0-9]{4}$·像以前一样匹配电话号码,但允许以分机或分机为前缀的可选五位数分机:
^(\(?[0-9]{3}\)?)?\-?[0-9]{3}\-?[0-9]{4}(\s*ext(ension)?[0-9]{5})?$发布于 2011-03-25 15:20:33
您可以使用正则表达式查看此站点的regex library
https://stackoverflow.com/questions/5429576
复制相似问题