Just a reminder that you need to be careful if there will be any nesting. Regex just isn't very good at this. Consider the following snippet:
(a,)b,(c,(d,)e,)
Based on your question, you would only want to match comma b
. The trick is that expressions are generally either completely greedy or completely un-greedy, with little middle ground.
A greedy expression would see the (
at the very beginning of the segment and the )
at the very end and take everything inside them, regardless that there are closing parentheses elsewhere. Nothing would be matched.
An ungreedy expression would take only the smallest set possible, starting from the beginning. It would match comma b
, but also see this segment as one unit: (c,(d,)
. Then it would proceed to also match comma e
, because it's already taken the last (
.
There are some engines that allow you to handle the nesting levels, but the expressions are usually ugly and hard to maintain: best to just avoid the feature unless you really understand it well.