Search code examples
regexdfa

RegEx: no more than two identical consecutive symbols


i'm struggling to get this regex. I need that to make a DFA, so I prefer JavaCC syntax rather than this.

∑ = {a, b}

L = no more than two identical consecutive symbols.

example: aa abab aabb bbabb bbaabbaab babbaabb

Thanks.


Solution

  • If the alphabet is only size two, then the following doesn't require backrefences. I apologize if the syntax isn't quite right: I've not used JavaCC.

    ("b")? ("b")? ("a" ("a")? "b" ("b")?)* ("a")? ("a")?