如上题 ,下面给出字符串
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后到传真号多少字符来来判断
------解决方案--------------------------------------------------------
http://www.cnblogs.com/time-is-life/articles/368186
------解决方案--------------------------------------------------------
/fax number is \d-\d{3}-\d{3}-\d{4}/
------解决方案--------------------------------------------------------
fax[^\d]+(\d+-\d+-\d+-\d+)
------解决方案--------------------------------------------------------
Regex r = new Regex( "fax number is \d-\d{3}-\d{3}-\d{4} ");
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);
}
------解决方案--------------------------------------------------------
看这是不是你要的结果
string yourStr = ...............;
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 ";
}
------解决方案--------------------------------------------------------
我就知道 过客要来
其实就是组匹配,楼主多看看正则的概念 很简单的
------解决方案--------------------------------------------------------
string str = @ "fax\snumber\sis\s(? <Fax> [\d-]+)\sOr ";
凑个热闹
我取的FAX 是数字和- 所以没位数
------解决方案--------------------------------------------------------
你说的意思我不太清楚,字符串格式不固定吗?
是不是要提取 fax number 后面第一次出现的号码?