regex - Backward slash missing from substitution in Scala -
i need construct complex strings , reason use """(triple quotes) delimiters string , regexps in scala.
in examples, such this:
"""foo""".r.replaceallin("foo", m => """backslash\andsometext""") // result = """backslashandsometext""" // where's backslash? the backslash gone form result.
what reason this? shouldn't strings wrapped in """ perform no escaping whatsoever??
you're supposed quote replacement string this way:
scala> import util.matching._ import util.matching._ scala> """foo""".r.replaceallin("foo", m => regex quotereplacement """backslash\andsometext""") res2: string = backslash\andsometext counter-example:
scala> "f(oo)".r.replaceallin("foo", m => """backslash$1\$andsometext""") res3: string = backslashoo$andsometext so dollar means group , backslash means escape dollar.
Comments
Post a Comment