How about not using Regex. Here's a snippet of code (for the console)
string[] myStringArray = new string[] { "abc123def456ghi", "abc123def456ghi789jkl", "abc123def", "123ghi", "abcdef","abc-654def" }; char[] numberSet = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }; char[] filterSet = new char[] {'a','b','c','d','e','f','g','h','i','j','k','l','m', 'n','o','p','q','r','s','t','u','v','w','x','y','z','-'}; foreach (string myString in myStringArray) { Console.WriteLine("your string - {0}",myString); int index1 = myString.LastIndexOfAny(numberSet); if (index1 == -1) Console.WriteLine("no number"); else { string mySubString = myString.Substring(0,index1 + 1); string prefix = myString.Substring(index1 + 1); Console.WriteLine("prefix - {0}", prefix); int index2 = mySubString.LastIndexOfAny(filterSet); string suffix = myString.Substring(0, index2 + 1); Console.WriteLine("suffix - {0}",suffix); mySubString = mySubString.Substring(index2 + 1); Console.WriteLine("number - {0}",mySubString); Console.WriteLine("_________________"); } } Console.Read();
Nika G.
source share