Saturday, May 11, 2013

How to validate data using regex?

See if the code below helps



static string[] testData = {"D[123] = string[] { \"Product A\", \"$230\" };",
"D[125] = string[] { \"Product B\", \"$30\" };",
"D[126] = string[] { \"Product C\", \"$50\" };"};
static void Main(string[] args)
{
Regex expr = new Regex(".*\\[(.*)\\]\\s*=.*\"(.*)\".*\"(.*)\" ");
foreach (string test in testData)
{
MatchCollection matches = expr.Matches(test);
string param1 = matches[0].Groups[1].ToString();
string param2 = matches[0].Groups[2].ToString();
string param3 = matches[0].Groups[3].ToString();
}






jdweng


No comments:

Post a Comment