Regex to validate this format

I’m trying to write a regex to validate a specific format. Here is it:

key=0(or)1;key=0(or)1;(repeated-or-not);key=0(or)1.

Or said otherwise:

  1. w
  2. sign
  3. 0 or 1
  4. ; sign only between elements. Not on the last element.
  5. All of previous repeated, or not.

The specificity is that the string can not end with a “;”.

For now I’ve this ^(?:[a-z]+=[01];?)+(?<!;)$ which is right but not completely. since foo=1;bar=0foo=0;bar=1passes but even tough this part bar=0foo=0is incorrect.

Here are my current regex and some testing strings: https://regex101.com/r/lX0xT7/1

Thank you for your help,
Cheers,


Source: regex

Leave a Reply