Need to split a string which is a combination of different materials. Need to extract all the materials by using a reg expression.
Possible inputs are
65%POLYESTER 30%COTTON 5%WOOL
95% COTTON DENIM 5% OTHERS
100% HS POLYPROPYLENE
100% POLYPROPYLENE HEATSET
Outputs should be
65% Polyester
30% Cotton
5% wool
Tried this
static IList<string> SplitContent(string input)
{
var list = new List<string>();
var regex = new Regex("\\d*\\.\\d+%?[A-Za-z \\s]");
var matches = regex.Matches(input);
foreach (Match item in matches)
{
list.Add(item.Value);
}
return list;
}
But it is not returning any matches. Can somebody help?
a better way would be
\d+matches 1 to many digits(\.\d+)?matches a dot and 1 to many digits 0 to 1 time(?)[a-zA-Z\s]+matches any character within that class 1 to many times..The match would break when there is a character which is not
[a-zA-Z\s]or when you come to end of the string