Regex to validate this format

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


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:

Thank you for your help,

Source: regex

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.