如上题 ,下面给出字符串
Please contact us for more information about this product. Our fax number is 1-800-123-4567 Or call us is 1-800-765-4321, or pager number is 1-800-777-1111 Our alternate fax number, which is only available during business hours, is 1-000-111-2222
我想获取fax后的传真号,如1-800-123-4567 1-000-111-2222而不是 call后的, 如1-800-765-4321,1-000-111-2222主要问题是如何跳过字符查找,
说明:字符串只是作为参考,不一定就只有取2个字符串要提取,是未知的,不要通过对fax后到传真号多少字符来来判断
Please contact us for more information about this product. Our fax number is 1-800-123-4567 Or call us is 1-800-765-4321, or pager number is 1-800-777-1111 Our alternate fax number, which is only available during business hours, is 1-000-111-2222
我想获取fax后的传真号,如1-800-123-4567 1-000-111-2222而不是 call后的, 如1-800-765-4321,1-000-111-2222主要问题是如何跳过字符查找,
说明:字符串只是作为参考,不一定就只有取2个字符串要提取,是未知的,不要通过对fax后到传真号多少字符来来判断
解决方案 »
- =========URL重写问题!===============
- 新手问题简单的很,先来先得
- 大家有没有见个这样的参数传递形式
- 对我而言有点复杂的问题,谁能挑战成功?
- Jqury单击每一行,动态获取选中的Value.
- web.config的討論﹐請大家發言﹐來者有分
- 关于WEB报表的考虑,给100
- 在Dropdownlist中如何显示特定的时间,高手来帮帮忙
- 求救:Asp.net的Oledbcommand记录插入后,为啥检查不到
- 如何有效地在ASP.NET中处理客户端的文件?
- 返回的头不同,如何改?
- 菜鸟求助 关于 GridView, DataTable, HashTable 间传值的综合操作
Match m = r.Match("你的字符串");
if(m.Success)
{
string str = "你的字符串".substring(m.index, "fax number is 0-000-000-0000".length);
你要的传真号 = str.remove(0,"fax number is ".length);
}
MatchCollection mc = Regex.Matches(yourStr, @"fax[\s\S]*?(?<fax>(\d+-)+\d+)", RegexOptions.IgnoreCase);
foreach(Match m in mc)
{
richTextBox2.Text += m.Groups["fax"].Value + "\n";
}
{
Regex r = new Regex("fax number is (?<faxnumber>\\d-\\d{3}-\\d{3}-\\d{4})");
Match m = r.Match("Please contact us for more information about this product.Our fax number is 1-800-123-4567 Or call us is 1-800-765-4321");
Console.WriteLine("faxnumber" + "------" + m.Groups["faxnumber"].Value);
Console.Read();
}
刚刚找到的方法,很不错
是不是要提取 fax number 后面第一次出现的号码?