Packages

  • package root

    This is the documentation for the Scala standard library.

    This is the documentation for the Scala standard library.

    Package structure

    The scala package contains core types like Int, Float, Array or Option which are accessible in all Scala compilation units without explicit qualification or imports.

    Notable packages include:

    Other packages exist. See the complete list on the right.

    Additional parts of the standard library are shipped as separate libraries. These include:

    • scala.reflect - Scala's reflection API (scala-reflect.jar)
    • scala.xml - XML parsing, manipulation, and serialization (scala-xml.jar)
    • scala.collection.parallel - Parallel collections (scala-parallel-collections.jar)
    • scala.util.parsing - Parser combinators (scala-parser-combinators.jar)
    • scala.swing - A convenient wrapper around Java's GUI framework called Swing (scala-swing.jar)

    Automatic imports

    Identifiers in the scala package and the scala.Predef object are always in scope by default.

    Some of these identifiers are type aliases provided as shortcuts to commonly used classes. For example, List is an alias for scala.collection.immutable.List.

    Other aliases refer to classes provided by the underlying platform. For example, on the JVM, String is an alias for java.lang.String.

    Definition Classes
    root
  • package scala

    Core Scala types.

    Core Scala types. They are always available without an explicit import.

    Definition Classes
    root
  • package util
    Definition Classes
    scala
  • package matching
    Definition Classes
    util
  • Regex
  • UnanchoredRegex

object Regex extends java.io.Serializable

This object defines inner classes that describe regex matches and helper objects.

Source
Regex.scala
Linear Supertypes
java.io.Serializable, AnyRef, Any
Content Hierarchy
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Regex
  2. Serializable
  3. AnyRef
  4. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Type Members

  1. class Match extends MatchData

    Provides information about a successful match.

  2. trait MatchData extends AnyRef

    This class provides methods to access the details of a match.

  3. class MatchIterator extends AbstractIterator[String] with Iterator[String] with MatchData

    A class to step through a sequence of regex matches.

    A class to step through a sequence of regex matches.

    This is an iterator that returns the matched strings.

    Queries about match data pertain to the current state of the underlying matcher, which is advanced by calling hasNext or next.

    When matches are exhausted, queries about match data will throw java.lang.IllegalStateException.

    See also

    java.util.regex.Matcher

Value Members

  1. def quote(text: String): String

    Quotes strings to be used literally in regex patterns.

    Quotes strings to be used literally in regex patterns.

    All regex metacharacters in the input match themselves literally in the output.

    Example:
    1. List("US$", "CAN$").map(Regex.quote).mkString("|").r
  2. def quoteReplacement(text: String): String

    Quotes replacement strings to be used in replacement methods.

    Quotes replacement strings to be used in replacement methods.

    Replacement methods give special meaning to backslashes (\) and dollar signs ($) in replacement strings, so they are not treated as literals. This method escapes these characters so the resulting string can be used as a literal replacement representing the input string.

    text

    The string one wishes to use as literal replacement.

    returns

    A string that can be used to replace matches with text.

    Example:
    1. "CURRENCY".r.replaceAllIn(input, Regex quoteReplacement "US$")
  3. object Groups

    An extractor object that yields the groups in the match.

    An extractor object that yields the groups in the match. Using this extractor rather than the original Regex ensures that the match is not recomputed.

    import scala.util.matching.Regex.Groups
    
    val date = """(\d\d\d\d)-(\d\d)-(\d\d)""".r
    val text = "The doc spree happened on 2011-07-15."
    val day = date replaceAllIn(text, _ match { case Groups(_, month, day) => s"$month/$day" })
  4. object Match

    An extractor object for Matches, yielding the matched string.

    An extractor object for Matches, yielding the matched string.

    This can be used to help writing replacer functions when you are not interested in match data. For example:

    import scala.util.matching.Regex.Match
    """\w+""".r replaceAllIn ("A simple example.", _ match { case Match(s) => s.toUpperCase })