I tried using regex to separate a comma and space string. The expression matches all but one of the cases. The code I tried is:
List<string> strNewSplit = new List<string>();
Regex csvSplit = new Regex("(?:^|,)(\"(?:[^\"]+|\"\")*\"|[^,]*)", RegexOptions.Compiled);
foreach (Match match in csvSplit.Matches(input))
{
strNewSplit.Add(match.Value.TrimStart(','));
}
return strNewSplit;
CASE1: "MYSQL, ORACLE", "C #, ASP.NET"
EXpectedOutput:
"MYSQL, ORACLE"
"C #, ASP.NET"
RESULT: PASS
CASE2: "MYSQL, ORACLE", "C #, ASP.NET"
ExpectedOutput:
"MYSQL, ORACLE"
"C #, ASP.NET"
Actual output:
"MYSQL, ORACLE"
"WITH#
ASP.NET "
RESULT: FAIL.
If I provided a decimal space between two DoubleQuotes, I did not get the corresponding output. Did I miss something? Please provide the best solution.
source
share