Reputation: 475
I have this pattern:
val smilepattern = "([:]) ([-]) ([) | | | (])".r
val smilepattern(colon, dash, arc) = ": - |"
println(colon + dash + arc)
my intention is to check the building of three smiles
, but HOW I can say that the dash ([-])
is optional? Because, a smile
can be :-)
and :)
???
Upvotes: 1
Views: 142
Reputation: 4999
You can make things optional by using ?
in regular expressions.
scala> ": )".matches("([:]) ([-]?) ([) | | | (])")
res1: Boolean = true
scala> ": - )".matches("([:]) ([-]?) ([) | | | (])")
res2: Boolean = true
Upvotes: 3