probably simple stuff but I don’t use regex that much.
Input: c1 = 7634, c2 = a,b, c3 = 8gd_, c4 = e,78
Desired Output:
c1 = 7634
c2 = a,b
c3 = 8gd_
c4 = e,78
Complexity (for me) – I don’t know how to define it so that for c2 it takes a,b with the comma. What I currently have:
(\w+)\s*=\s*((?:[^,].*?[^,])?)
trails the b.
Thanks upfront!
>Solution :
You can use
(\w+)\s*=\s*(.*?)(?=\s*,\s*\w+\s*=|$)
See the regex demo
Details:
(\w+)– Group 1: one or more word chars\s*=\s*– a=sign enclosed with zero or more whitespaces(.*?)– Group 2: any zero or more chars other than line break chars as few as possible(?=\s*,\s*\w+\s*=|$)– immediately followed with a comma inside optional whitespaces + one or more word chars, zero or more whitespaces, and a=sign, or end of string.
Add \s* before $ if there can be trailing whitespaces.