[Solved] Need help to split a string [closed]


I believe I have found a solution. Not sure if it is the best way, but I am using regex to extract what need

string pattern = @"[0-9][0-9 /.,]+[a-zA-Z ]+";
string input = line;

var result = new List<string>();

foreach (Match m in Regex.Matches(input, pattern))
   result.Add(m.Value.Trim());

return result;

This piece of code returns what I need such as

new[] { "1 kg sugar", "100 pound flour", "10 g salt", "1 1/4 cup of flour", "1.5  piece of stuff or", "1.5 cup of water" }

From there, I’ll loop to remove all undesired words such as ‘or’ and Trim() again.

solved Need help to split a string [closed]