Browse files

SI-8107: Add Regex.quote

  • Loading branch information...
1 parent 6834cc2 commit 780ceca6a39ddb2d9ba632cc8153c737707a75eb @qerub qerub committed Oct 19, 2013
Showing with 8 additions and 0 deletions.
  1. +8 −0 src/library/scala/util/matching/Regex.scala
View
8 src/library/scala/util/matching/Regex.scala
@@ -704,6 +704,14 @@ object Regex {
def replace(rs: String) = matcher.appendReplacement(sb, rs)
}
+ /** Quotes strings to be used literally in regex patterns.
+ *
+ * All regex metacharacters in the input match themselves literally in the output.
+ *
+ * @example {{{List("US$", "CAN$").map(Regex.quote).mkString("|").r}}}
+ */
+ def quote(text: String): String = Pattern quote text
+
/** Quotes replacement strings to be used in replacement methods.
*
* Replacement methods give special meaning to backslashes (`\`) and

0 comments on commit 780ceca

Please sign in to comment.