I believe this regex would help you break up your string into the relevant components:
([A-Za-z]{1,}[0-9.]*|[0-9.]{1,}[A-Za-z]*)
Just use match collections like so:
string pattern = "([A-Za-z]{1,}[0-9.]*|[0-9.]{1,}[A-Za-z]*)";
string input = "z5 100c x87.50.";
MatchCollection matches = Regex.Matches(input, pattern);
foreach (Match match in matches)
{
Console.WriteLine(match.Groups[1].Value);
}
would give you:
z5
100c
x87.50.
and then you could further analyze as needed.
You could even do it all at once using named match groups to make your life a bit easier... something like:
string pattern = "(?<price_structure>[0-9.]{1,}[c]{1,})|(?<year_month>[z]{1,}[0-9]{1,})";
string input = "z5 100c x87.50.";
MatchCollection matches = Regex.Matches(input, pattern);
foreach (Match match in matches)
{
Console.WriteLine("price-structure: " + match.Groups["price_structure"].Value);
Console.WriteLine("year-month: " + match.Groups["year_month"].Value);
}
which would give you:
price-structure:
year-month: z5
price-structure: 100c
year-month:
if you wanted to break this down even further you could do something like (note that usage of + in the below is equivalent to {1,} in above examples):
(?<price>[0-9.]+)(?<structure>[c]+)|(?<year>[zx]+)(?<month>[0-9.]+)
I am separating price/structure and year/month with the or operator | to illustrate how you can keep the groups together in case it is contextually important that, for instance, c would only mean "structure" if first preceded by a price. I have also added x to year to illustrate how you can easily add other characters to the set of viable match characters as PhatWrat points out below.
The new regex will result in:
z5 has 4 groups:
(price)
(structure)
z (year)
5 (month)
100c has 4 groups:
100 (price)
c (structure)
(year)
(month)
x87.50. has 4 groups:
(price)
(structure)
x (year)
87.50. (month)
you can try this out with this online testing site: http://derekslager.com/blog/posts/2007/09/a-better-dotnet-regular-expression-tester.ashx