First, add this
using namespace;
statement:
using System.Text.RegularExpressions;
Then, try this:
string str = "your string here";
MatchCollection matches = Regex.Matches(str, @"\d+(\.\d+)?");
List<string> numbers = new List<string>();
foreach (Match m in matches)
{
numbers.Add(m.Value);
}
If you don't want a list of strings, but a list of doubles, try this:
string str = "your string here";
MatchCollection matches = Regex.Matches(str, @"\d+(\.\d+)?");
List<double> numbers = new List<double>();
foreach (Match m in matches)
{
numbers.Add(Double.Parse(m.Value, new System.Globalization.NumberFormatInfo() { NumberDecimalSeparator = "." }));
}
My regular expression
\d+(\.\d+)?
looks for numbers with and without decimal point. If you only want to match numbers with a decimal point, remove the parentheses and the question mark:
\d+\.\d+