I have regular expressions like below. Ancak tam olarak doğru bir şekilde regex yazamadım.
keys:value,keyx:values,keyt:valus,........ OR keys:value
How can I perform an exact match both ways?
regex: (^\w+:\w+|(,))
>Solution :
For a single or multiple occurrence of the key:value parts and matching only word characters, you can match the first occurrence and optionally repeat a comma and then then same pattern using a repeating group.
^\w+:\w+(?:,\w+:\w+)*$
^Start of string\w+:\w+Match the first key:value occurrence(?:,\w+:\w+)*Optionally repeat using*a comma and again a key:value pair$End of string
See the matches on regex 101.