开发者

Regex to extract digits followed by specific word

Using Regex, I want to extract digi开发者_如何转开发ts which are followed by a specific word.

The number of digits is not finite.

Sample input:

My address is 1234@abc.com and you can send SMS to me.

Expected Result.

1234

In this case, the specific word is @abc.com, and the digits followed by this word need to be extracted.


Use the regular expression groups : on MSDN.

In C#, try this :

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");


You will need to match 1234@abc.com and use a grouping to extract the digits:

(\d+)\@abc.com


.* (\d+)@abc\.com .* should work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜