生の String は次のように宣言できることを知っています。
val foo: String = """foo"""
また
val foo: String = raw"foo"
ただし、文字列型の val がある場合、どうすれば raw に変換できますか? 例えば:
// val toBeMatched = "line1: foobarfoo\nline2: lol"
def regexFoo(toBeMatched: String) = {
val pattern = "^.*foo[\\w+]foo.*$".r
val pattern(res) = toBeMatched /* <-- this line induces an exception
since Scala translates '\n' in string 'toBeMatched'. I want to convert
toBeMatched to raw string before pattern matching */
}