Lucy
Lucy

Reputation: 491

regular expression to define a language

Can some one help with defining a regex for language L while strings in L don't contain 101 as a substring? (if only 0s and 1s are allowed)

I already have (1|0)*[^(101)] but it does reject all the strings in the language.

Upvotes: 2

Views: 54

Answers (1)

anubhava
anubhava

Reputation: 785991

Add this negative lookahead:

^(?!.*?101)[01]+$

in front of your regex.

Upvotes: 2

Related Questions