これは、エスケープされた引用符を含まない文字列に対して機能します (それらは、偶数の引用符のカウントをオフバランスにするため)。
Regex regexObj = new Regex(
@"\w+~[\d.]* # Match an alnum word, tilde, optional digits/dots
(?= # only if there follows...
[^""]* # any number of non-quotes
(?: # followed by...
""[^""]* # one quote, and any number of non-quotes
""[^""]* # another quote, and any number of non-quotes
)* # any number of times, ensuring an even number of quotes
[^""]* # Then any number of non-quotes
$ # until the end of the string.
) # End of lookahead assertion",
RegexOptions.IgnorePatternWhitespace);
エスケープされた引用符に対処する必要がある場合は、もう少し複雑になります。
Regex regexObj = new Regex(
@"\w+~[\d.]* # Match an alnum word, tilde, optional digits/dots
(?= # only if there follows...
(?:\\.|[^\\""])* # any number of non-quotes (or escaped quotes)
(?: # followed by...
""(?:\\.|[^\\""])* # one quote, and any number of non-quotes
""(?:\\.|[^\\""])* # another quote, and any number of non-quotes
)* # any number of times, ensuring an even number of quotes
(?:\\.|[^\\""])* # Then any number of non-quotes
$ # until the end of the string.
) # End of lookahead assertion",
RegexOptions.IgnorePatternWhitespace);