search multiple texts with named groups using regular expressions
Published: 24. October 2011 | Updated: 26. October 2011License: Microsoft Public License (MS-PL)
Categories: Framework » Regex
Tags: C# Regex Text
Import namespace
using System.Text.RegularExpressions;
Code
string input = "abcd4987xyz2279wwa"; string pattern = "(?<number>[0-9]+)"; MatchCollection matches = Regex.Matches(input, pattern); foreach (Match match in matches) { if (match.Success) { string result = match.Groups["number"].Value; Console.WriteLine(result); } }Console Output:
4987
2279
2279
| Send us feedback about this snippet » |





