@@ -59,7 +59,7 @@ import java.util.regex.{ Pattern, Matcher }
59
59
*
60
60
* {{{
61
61
* "2004-01-20" match {
62
- * case date(year, month, day) => s"$year was a good year for PLs."
62
+ * case date(year, month, day) => s"\ $year was a good year for PLs."
63
63
* }
64
64
* }}}
65
65
*
@@ -78,7 +78,7 @@ import java.util.regex.{ Pattern, Matcher }
78
78
*
79
79
* {{{
80
80
* "2004-01-20" match {
81
- * case date(year, _*) => s"$year was a good year for PLs."
81
+ * case date(year, _*) => s"\ $year was a good year for PLs."
82
82
* }
83
83
* }}}
84
84
*
@@ -121,7 +121,7 @@ import java.util.regex.{ Pattern, Matcher }
121
121
* val mi = date.findAllIn(dates)
122
122
* while (mi.hasNext) {
123
123
* val d = mi.next
124
- * if (mi.group(1).toInt < 1960) println(s"$d: An oldie but goodie.")
124
+ * if (mi.group(1).toInt < 1960) println(s"\ $d: An oldie but goodie.")
125
125
* }
126
126
* }}}
127
127
*
@@ -165,8 +165,8 @@ import java.util.regex.{ Pattern, Matcher }
165
165
* {{{
166
166
* val redacted = date.replaceAllIn(dates, "XXXX-XX-XX")
167
167
* val yearsOnly = date.replaceAllIn(dates, m => m.group(1))
168
- * val months = (0 to 11).map { i => val c = Calendar.getInstance; c.set(2014, i, 1); f"$c%tb" }
169
- * val reformatted = date.replaceAllIn(dates, _ match { case date(y,m,d) => f"${months(m.toInt - 1)} $d, $y" })
168
+ * val months = (0 to 11).map { i => val c = Calendar.getInstance; c.set(2014, i, 1); f"\ $c%tb" }
169
+ * val reformatted = date.replaceAllIn(dates, _ match { case date(y,m,d) => f"\ ${months(m.toInt - 1)} \ $d, \ $y" })
170
170
* }}}
171
171
*
172
172
* Pattern matching the `Match` against the `Regex` that created it does not reapply the `Regex`.
@@ -191,7 +191,7 @@ import java.util.regex.{ Pattern, Matcher }
191
191
* @param groupNames A mapping from names to indices in capture groups
192
192
*
193
193
* @define replacementString
194
- * In the replacement String, a dollar sign (`$`) followed by a number will be
194
+ * In the replacement String, a dollar sign (`\ $`) followed by a number will be
195
195
* interpreted as a reference to a group in the matched pattern, with numbers
196
196
* 1 through 9 corresponding to the first nine groups, and 0 standing for the
197
197
* whole match. Any other character is an error. The backslash (`\`) character
@@ -380,7 +380,7 @@ class Regex private[matching](val pattern: Pattern, groupNames: String*) extends
380
380
* {{{
381
381
* val madhatter = "(h)(?=(at[^a]+))".r
382
382
* val madhats = madhatter.findAllMatchIn(hathaway).map {
383
- * case madhatter(x,y) => s"$x $y"
383
+ * case madhatter(x,y) => s"\$x\ $y"
384
384
* }.toList // List(hath, hatth, hattth, hatttt)
385
385
* }}}
386
386
*
@@ -494,7 +494,7 @@ class Regex private[matching](val pattern: Pattern, groupNames: String*) extends
494
494
* import scala.util.matching.Regex
495
495
* val datePattern = new Regex("""(\d\d\d\d)-(\d\d)-(\d\d)""", "year", "month", "day")
496
496
* val text = "From 2011-07-15 to 2011-07-17"
497
- * val repl = datePattern replaceAllIn (text, m => s"${m group "month"}/${m group "day"}")
497
+ * val repl = datePattern replaceAllIn (text, m => s"\ ${m group "month"}/\ ${m group "day"}")
498
498
* }}}
499
499
*
500
500
* $replacementString
@@ -517,7 +517,7 @@ class Regex private[matching](val pattern: Pattern, groupNames: String*) extends
517
517
* {{{
518
518
* import scala.util.matching.Regex._
519
519
*
520
- * val vars = Map("x" -> "a var", "y" -> """some $ and \ signs""")
520
+ * val vars = Map("x" -> "a var", "y" -> """some \ $ and \ signs""")
521
521
* val text = "A text with variables %x, %y and %z."
522
522
* val varPattern = """%(\w+)""".r
523
523
* val mapper = (m: Match) => vars get (m group 1) map (quoteReplacement(_))
@@ -564,7 +564,7 @@ class Regex private[matching](val pattern: Pattern, groupNames: String*) extends
564
564
* the entire String matches in extractor patterns.
565
565
*
566
566
* Normally, matching on `date` behaves as though the pattern were
567
- * enclosed in anchors, `"^pattern$"`.
567
+ * enclosed in anchors, `"^pattern\ $"`.
568
568
*
569
569
* The unanchored `Regex` behaves as though those anchors were removed.
570
570
*
@@ -578,7 +578,7 @@ class Regex private[matching](val pattern: Pattern, groupNames: String*) extends
578
578
* val date(year, month, day) = "Date 2011-07-15" // OK
579
579
*
580
580
* val copyright: String = "Date of this document: 2011-07-15" match {
581
- * case date(year, month, day) => s"Copyright $year" // OK
581
+ * case date(year, month, day) => s"Copyright \ $year" // OK
582
582
* case _ => "No copyright"
583
583
* }
584
584
* }}}
@@ -766,7 +766,7 @@ object Regex {
766
766
*
767
767
* val date = """(\d\d\d\d)-(\d\d)-(\d\d)""".r
768
768
* val text = "The doc spree happened on 2011-07-15."
769
- * val day = date replaceAllIn(text, _ match { case Groups(_, month, day) => s"$month/$day" })
769
+ * val day = date replaceAllIn(text, _ match { case Groups(_, month, day) => s"\ $month/\ $day" })
770
770
* }}}
771
771
*/
772
772
object Groups {
@@ -904,21 +904,21 @@ object Regex {
904
904
*
905
905
* All regex metacharacters in the input match themselves literally in the output.
906
906
*
907
- * @example {{{List("US$", "CAN$").map(Regex.quote).mkString("|").r}}}
907
+ * @example {{{List("US\ $", "CAN\ $").map(Regex.quote).mkString("|").r}}}
908
908
*/
909
909
def quote (text : String ): String = Pattern quote text
910
910
911
911
/** Quotes replacement strings to be used in replacement methods.
912
912
*
913
913
* Replacement methods give special meaning to backslashes (`\`) and
914
- * dollar signs (`$`) in replacement strings, so they are not treated
914
+ * dollar signs (`\ $`) in replacement strings, so they are not treated
915
915
* as literals. This method escapes these characters so the resulting
916
916
* string can be used as a literal replacement representing the input
917
917
* string.
918
918
*
919
919
* @param text The string one wishes to use as literal replacement.
920
920
* @return A string that can be used to replace matches with `text`.
921
- * @example {{{"CURRENCY".r.replaceAllIn(input, Regex quoteReplacement "US$")}}}
921
+ * @example {{{"CURRENCY".r.replaceAllIn(input, Regex quoteReplacement "US\ $")}}}
922
922
*/
923
923
def quoteReplacement (text : String ): String = Matcher quoteReplacement text
924
924
}
0 commit comments