1

Pls see the following DFA https://i.stack.imgur.com/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 ?

om-nom-nom
  • 62,329
  • 13
  • 183
  • 228
k r
  • 409
  • 2
  • 6
  • 13

1 Answers1

1

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

p|(q|pq)(pq)*p?
Qtax
  • 33,241
  • 9
  • 83
  • 121
  • Wow thank you. I tried replacing + with |, and below works perfect. scala> val regex = "p|(q|pq)(pq)*(|p)".r regex: scala.util.matching.Regex = p|(q|pq)(pq)*(|p) – k r Jun 11 '12 at 21:55