This is the case where Regular Expressions do not play well. You need a split functions by ',' and blank space. On .NET the best way is using
string.Split
, on other platforms something like that is still the best options.
I could give more details if you tagged your platform/language. Do it now!
[EDIT per discussion, below]
For example of solution for a similar problem, please see my article:
Enumeration-based Command Line Utility[
^].
In the code for this article, I had a problem to make a good simulator to test command line in tricky situation where quotation marks are used to pass command line argument containing blank spaces. .NET parses a raw single-string command line into the array of strings in some cunning way, splitting the line by blank spaces but preserving the blank spaced in quoted fragments of the command line. It can even split more or less reasonably if the user makes mistakes in balancing of the quotation marks. I need to simulate this in order to accelerate testing.
The section "6. Testing" of the article explains this problem and the code. Look at this section to find out where this algorithm is implemented in my demo/test code and locate this code. I analyzed the problem from different stand points and concluded that Regular expression would not be really helpful, so I ended up with direct string calculations.
Hope it can be useful.
—SA