In this post, we will see how to resolve Repeated patterns in regex
Question:I tried to explain the pattern below. The key-value pair parsing should succeed if the values are separated by a new line or a comma. But separators should not create empty values, like a comma at the beginning, at the end or two consecutive commas, etc. So that I could get only key-value pairs by just calling capture groups.
Edit: The “key” and “value” have their own patterns and I have solved them already. I am struggling with repeating capture groups. Just to clarify.
Best Answer:Adding a simple OR-Block to your regex seems to do the job for your provided example:
If you have better answer, please add a comment about this, thank you!