Can languages that are not closed against the Kleene star be regular? I've been working on finding a regular expression for the following language for quite some time now ($\Sigma =\text{{0, 1}}$):


  $
\text{L = {w | the difference between the number of 0's and 1's in each prefix of the word is less than or equal to 1}}$


I haven't been able to find an expression for this particular language so far, so I was wondering if the language is regular at all.

The following came to mind, but I'm pretty dubious about its validity :


  Since $010$ belongs to said language, and by concatenation $010010$ does not, it would follow that this language isn't closed under Kleene star, hence it's not regular.


Am I wrong? If so, could you help with finding the solution to this problem?

Regarding the meaning of prefix in this context, the prefixes of the string $abcd$ are $\text{{$abcd, abc, ab, a$}}$.
No, your argument is not correct.

The "hence it's not regular" doesn't follow.  Not every regular language is closed under Kleene star.  Some regular languages aren't closed under Kleene star.  I think you've misunderstood the closure property: the closure property states "If $L$ is regular, then $L^*$ is regular".  Note that you can still have a regular language where $L \ne L^*$.

To learn how to solve this question correctly, you may want to check out our reference questions.  See especially How to prove a language is regular?, Show whether the language with almost as many 0 as 1 in every prefix is regular, Language where every prefix has almost equal a&#39;s and b&#39;s.