Noise is good. Though the sound of crickets chirping can also be pleasant on summer nights.
Acknowledging the good work someone did on the Scaladoc:
http://www.scala-lang.org/archives/downloads/distrib/files/nightly/docs/library/index.html#scala.util.matching.Regex
It seems the bit about flags was deemed important enough to document out of the gate (in older scaladoc).
Simple demo follows. It would be nice if Scaladoc had a "copy example to clipboard" button.
I especially like the doc: "Regex does not provide a method that returns a Boolean."
Because, of course, you're thinking, what tells me if it matches, t/f? So maybe it would be nice to be able to search/sort scaladoc by result type.
package myregex
import scala.util.matching._
import scala.util.matching.Regex.Match
import java.util.regex.Pattern
import java.util.regex.Pattern._
class MyRegex(r: String, gs: String*) extends Regex(r, gs: _*) {
override val pattern = Pattern.compile(r, CASE_INSENSITIVE | MULTILINE)
}
object Test {
val months = Map(1 -> "Jan", 2 -> "Feb", 3 -> "Mar",
4 -> "Apr", 5 -> "May", 6 -> "Jun",
7 -> "Jul", 8 -> "Aug", 9 -> "Sep",
10 -> "Oct", 11 -> "Nov", 12 -> "Dec")
def main(args: Array[String]) {
val dateP2 = new MyRegex("""(\d\d\d\d)-(\d\d)-(\d\d)""", "year", "month", "day")
val dateP3 = new MyRegex("""JUL (\d\d), (\d\d\d\d)""", "day", "year")
def reformatDate(text: String) = dateP2 replaceAllIn ( text, (m: Match) =>
"%s %s, %s" format (months((m group "month").toInt), m group "day", m group "year")
)
def inJuly(text: String) = (dateP3 findFirstIn text).nonEmpty
val j = reformatDate("2011-07-15")
println(s"${j} ${inJuly(j)}")