I have to check if a string follows the following patterns:
Field1=value1
Field1=value1,Field2=value2
7645a=fds23,Field2=dsd$
The words ‘field1’, ‘value1’ don’t count, the important thing is that it has to be something=something and if there is more than 1, it should be a comma for each pair.
I reached the following regex:
((\w+)[^=])=((\w+)[^=])
"Match any one or more word except if it has =, then there should be an = and then match any one or more word except if it has =".
The thing is, it does take the comma but I think is because of \w. I don’t think this is correct.
I’m using https://regexr.com/ to check for the correct regular expression.
>Solution :
If you need to match symbols like $, then don’t use \w. This satisfies all your conditions:
(?:([^,=\n]+)=([^,=\n]+))(?:,([^,=\n]+)=([^,=\n]+))*