This regex expression should find any extra commas the way your are wanting.
This will select all repeating inside/trailing commas
(?<=\w): positive look-behind, match any word character; non-selecting
\,+: if 1 is satisfied, select as many comma literals as possible, stop where 3 is satistified
(?=$|\,): positive look-ahead, match end-of-string or a single comma literal, non-selecting
This will select all leading commas
(?<=^): positive look-ahead, match the start-of-string, non-selecting
\,+: if 1 is satisfied, then select all comma literals possible
Then using Python's
re.sub() you can replace them with an empty string.
orig_str = ",,,0,12,13,,,a,,56,67,90,,,"
new_str = re.sub(r"(?<=\w)\,+(?=$|\,)", r"", orig_str)
new_str = "0,12,13,a,56,67,90"
You should examine why are you doing what you are doing. This is kind of workaround is what is often called a 'code smell' in the programming domain. It is trying to use a system in a capacity where there is a better solution; using a hammer to drive a screw.
You may be very skilled in what you are doing and I obviously don't have the insight you do for your project; so choose to ignore this if you want. But from the outside, this seems to be an overcomplication or not choosing your project parameters more carefully.
As user30184 pointed out, if you remove separators how do you know what value was selected in which field? If the final values of the string is treated all equally then why treat the questions differently? Why not have a user select all values in one question. Or do you need define your questions better?
Again, do take a minute to review your decision. Your data schema is arguably the most important part of any GIS project, should be the most examined and toiled. It is probably the most difficult to fix afterwards.
With a bit more information I don't think asking help for schema design in another question would be inappropriate here at GIS.SE or potentially CrossValidate.SE.
10,12,13;;;;56,67,89Repeated field separators are needed in CSV and they present nulls as field value.