John Roberts
John Roberts

Reputation: 5986

Flex/Lex: Regular Expression Won't Compile

I am trying to write a flex program that operates on text consisting of all strings of a's, b's, and c's. The string I need to match is of the form abxba, where x does not contain ba as a substring (for example, abccabba, but not abccbaba). This is the lex regular expression I'm trying to use to do this, but it won't compile:

^[a]{1}[b]{1}[abc|cab|bca|acb|ac|ca|ab|bc|cb][b]{1}[a]{1}$

I'm a bit new to lex/flex, so I apologize if this is very basic. Anyone know what's wrong?

Upvotes: 0

Views: 274

Answers (2)

geekie12
geekie12

Reputation: 11

Try also using ^ab[a(b+c)*]*ba$ and see if that works.

Upvotes: 0

Michael Day
Michael Day

Reputation: 1015

This will work: ^ab(a|c|b+[c])*b+a$

Upvotes: 1

Related Questions