# Formal Languages - Matching this regular expression

I'm trying to write a regular expression over the alphabet {0,1,2} for the language in which every 1 is preceded by 0. For example 2200201010, 01022020102012 are strings of the language.

I've tried with this:

(0+2)*(01)*(0+2)*(01)*(0+2)*


, where '+' means {0,2,00,02,20,22,.....}. Is this reg-exp correct? Thank you

• Why not? The '*' include zero, one or more – Alberto Jun 18 '17 at 16:09
• Right. But it doesn't include 01201201. – Yuval Filmus Jun 18 '17 at 16:20
• Right. Should I put that expression in another ( ... ) * ? – Alberto Jun 18 '17 at 17:18
• Something of this sort. – Yuval Filmus Jun 18 '17 at 17:33
• We discourage "please check whether my answer is correct" questions, as only "yes/no" answers are possible, which won't help you or future visitors. See here and here. Can you edit your post to ask about a specific conceptual issue you're uncertain about? As a rule of thumb, a good conceptual question should be useful even to someone who isn't looking at the problem you happen to be working on. If you just need someone to check your work, you might seek out a friend, classmate, or teacher. – D.W. Jun 19 '17 at 6:09

(01+2+0)* this may work because the string will contain any combination of given inputs and a 1 will always be preceded by a 0.