Created
August 30, 2011 21:06
-
-
Save jrwren/1182046 to your computer and use it in GitHub Desktop.
why does this regex result in two matches?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public virtual string[] _ParseCsvFormat(string value) | |
{ | |
//var regexstr = @"(?:(?:""(?<m>[^""]*?,[^""]*?)""|(?<m>[^,]*)))(?:,|$)"; | |
var regexstr = @" | |
(?: | |
(?: | |
"" | |
(?<m>[^""]*?,[^""]*?) | |
"" | |
| | |
(?<m>[^,]*) | |
) | |
) | |
(?:,|$) | |
"; | |
var regex = new Regex(regexstr, RegexOptions.IgnorePatternWhitespace); | |
var matches = regex.Matches(value); | |
return matches.Cast<Match>() | |
.Select(m => m.Groups["m"].Value) | |
.ToArray(); | |
} | |
_ParseCsvFormat("a"); //results in {"a",""} and I was hoping for {"a"} | |
I don't see from where the second match is coming. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment