Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I provide the second match in my regular expression and do full validation?

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading