Considering a path such as
var dir = new File("""c:\test\project1""");
How do I easily in Scala escape/quote this so it can be used safely in regular expressions
val extractRelativePath = (dir.getAbsolutePath() + """(.*)""").r
I tried using
dir.getAbsolutePath().replaceAll("\\", "\\\\");
but this does not work. as the following example shows
def main(args: Array[String]): Unit = {
var base = new File("""c:\test\project1""");
val extractRelativePath = (base.getAbsolutePath() + """(.*)""").r
var dir = new File("""c:\test\project1\somedir""");
var extractRelativePath(rel) = dir.getAbsolutePath().replaceAll("\\\\", "\\\\")
}
Also is there not some standard functionality that does this safely across platforms like Pattern.quote ?.