regexscalajflap

Trying to use a jflap regex in scala


Pls see the following DFA https://i.sstatic.net/iH3RM.png

created via JFLAP. When I convert to regex, JFLAP gives:

  p+(q+pq)(pq)*(λ+p)

When I paste it in the Scala REPL :

  scala> val regex = "p+(q+pq)(pq)*(+p)".r
  java.util.regex.PatternSyntaxException: Dangling meta character '+' near index 14
  p+(q+pq)(pq)*(+p)
                ^
      at java.util.regex.Pattern.error(Unknown Source)

I have two simple questions.

  1. Is that the right regex ? Why does it include a λ ?

  2. How do I use it in Scala since the λ doesn't show up correctly when I paste in repl ?


Solution

  • In formal regular expression notation + means "or". The regex you want to use is something like:

    p|(q|pq)(pq)*p?