【发布时间】:2016-10-13 11:56:39
【问题描述】:
使用正则表达式,我想提取后跟特定单词的数字。
位数不是有限的。
示例输入:
My address is 1234@abc.com and you can send SMS to me.
预期结果。
1234
本例中具体单词为@abc.com,需要提取该单词后面的数字。
【问题讨论】:
使用正则表达式,我想提取后跟特定单词的数字。
位数不是有限的。
示例输入:
My address is 1234@abc.com and you can send SMS to me.
预期结果。
1234
本例中具体单词为@abc.com,需要提取该单词后面的数字。
【问题讨论】:
使用正则表达式组:on MSDN。
在 C# 中,试试这个:
string pattern = @"(\d+)@abc\.com";
string input = "My address is 15464684@abc.com and you can send SMS to me";
Match match = Regex.Match(input, pattern);
// Get the first named group.
Group group1 = match.Groups[1];
Console.WriteLine("Group 1 value: {0}", group1.Success ? group1.Value : "Empty");
【讨论】:
您需要匹配 1234@abc.com 并使用分组来提取数字:
(\d+)\@abc.com
【讨论】:
.* (\d+)@abc\.com .* 应该可以工作。
【讨论】: