in reply to Re: Regular Expression, Catching Variables
in thread Regular Expression, Catching Variables
That's exactly what I was thinking. The only problem with a split (which it would seem to me in the OP's case the character to split on would be the commas) is that there are instances (e.g., in the OP's case of "which lab(s) are being used" for the activity might be separated by commas that the OP doesn't want to split on) where the commas need to *not* be split out.
When I've done this sort of thing I have used a regex to go into the string and find the instances of commas that I wanted to keep (e.g., in this case any that appear between opening and closing parentheses) and change them to some other character such as a semi-colon so that it still carries the information but doesn't interfere with the splitting.
I use CSV files a lot and split is almost always my friend. I rarely have had occasions that the OP is encountering, however, where I have had imbedded commas that needed to be *not* split upon.
Consequently, on those infrequent occasions, I almost always have to "re-invent" a regex to find all of the non-splitting commas and change them to some other meaningful character (e.g., semi-colons) before doing the split. The regex always seem to beg for lookahead or lookbehind and I'm such a novice with regex'es that it is reoccuringly a major effort to get the regex right. So I'm ashamed that I can't be of help to the OP for that part.
IMHO, okol's approach using split() is my preferred approach. But, of course, the OP may prefer or need to use regex's for all of it and I certainly respect that.
|
|---|