How to split a number from a regex expression in c#?
I suggest extracting Matches
instead of Split
:
string exp = "$(2.1)+$(3.2)-tan($(23.2)) * 0.5";
var doubleArray = Regex
.Matches(exp, @"\$\((?<item>[0-9.]+)\)")
.OfType<Match>()
.Select(match => match.Groups["item"].Value)
.ToList();
Console.WriteLine(string.Join("; ", doubleArray));
Outcome:
2.1; 3.2; 23.2