javadba javadba - 1 year ago 76
Scala Question

Error: value r is not a member of String for a simple regex

For the following straightforward regex that works fine in the


val tsecs = """[^\d]+([\d]+)*""".r
tsecs: scala.util.matching.Regex = [^\d]+([\d]+)*

Why would it not compile - either in Intellij or on the commandline via
mvn compile

val tsecs = """[^\d]+([\d]+)*""".r

error: value r is not a member of String
[ERROR] val tsecs = """[^\d]+([\d]+)*""".r

The version is scala 2.10.5 in all cases.

Answer Source

There are a few ways to disable Predef.

import scala.Predef.{wrapString => _, augmentString => _,  _}

object Test extends App {
  def r = "x".r


object Test extends App {
  val wrapString, augmentString = 42
  def r = "x".r

Or compile with -Yno-imports.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download