Regex to validate this format -


i'm trying write regex validate specific format. here 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 between elements. not on last element.
  5. all of previous repeated, or not.

the specificity string can not end ";".

for i've ^(?:[a-z]+=[01];?)+(?<!;)$ right not completely. since foo=1;bar=0foo=0;bar=1passes tough part bar=0foo=0is incorrect.

here current regex , testing strings: https://regex101.com/r/lx0xt7/1

thank help, cheers,

you can use regex:

^\w+=[01](?:;\w+=[01])*$ 

updated regex demo


Comments