Let say I have a string:
val pattern = "BOTH SAEM|O RLY?|YA RLY|NO WAI|OIC|WTF?|OMG|GTFO|OMGWTF".r
val pattern = "BOTH SAEM|O RLY\?|YA RLY|NO WAI|OIC|WTF\?|OMG|GTFO|OMGWTF".r
invalid escape character
You need to escape the question mark twice:
val pattern = "BOTH SAEM|O RLY\\?|YA RLY|NO WAI|OIC|WTF\\?|OMG|GTFO|OMGWTF".r
The explanation here is that you want to feed
\? into the regex engine, to tell it to treat the question mark as a literal. But you need to escape the backslash itself, so that Scala won't think you're trying to escape the question mark in the Scala code.