View Full Version : Regular expression


mif
09-23-02, 03:42 PM
Hi I am new in learning regular expressions and having trouble understanding one example...
it is where you have to write a regular expression for the set of strings containing no more than three a's in a row. The alphabet
is {a,b}.
So what i thought doing is: after you get 3 a's in a row, they have to be separated by at least one b..also, you have 3 cases:
a
aa
aaabb*
so i came up with this regular expression:

b*(a|aa|aaabb*)*bb*
but it does not accept the string aaa.
so i am stuck..is my reasoning right at least?
anyone who is good at regular expressions?
Thanks a lot guys!:)

Porfiry
09-23-02, 06:54 PM
How about:

b*(a|aa|aaa)(b+(a|aa|aaa))*

where b+ means the same as bb* (one or more)

?

allant
09-24-02, 07:10 PM
Moi is not going to give you the exact answer but will help. Look at like this :- What you need to look for starts with the beginning of the line (^) or a B then followed by one two or three A's then followed by the end of line $ or a B.

If you are thinking that it could be any charcters then a B to start then you are right, but then pattern matching will match anywhere on the line, so ...

Get back to us if this is not enough help.