scala.util.matching

UnanchoredRegex

trait UnanchoredRegex extends Regex

Linear Supertypes
Regex, Serializable, java.io.Serializable, AnyRef, Any
Type Hierarchy Learn more about scaladoc diagrams
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. UnanchoredRegex
  2. Regex
  3. Serializable
  4. Serializable
  5. AnyRef
  6. Any
Implicitly
  1. by any2stringadd
  2. by StringFormat
  3. by Ensuring
  4. by ArrowAssoc
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Value Members

  1. final def !=(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Definition Classes
    AnyRef → Any
  3. def +(other: String): String

    Implicit information
    This member is added by an implicit conversion from UnanchoredRegex to any2stringadd[UnanchoredRegex] performed by method any2stringadd in scala.Predef.
    Definition Classes
    any2stringadd
  4. def ->[B](y: B): (UnanchoredRegex, B)

    Implicit information
    This member is added by an implicit conversion from UnanchoredRegex to ArrowAssoc[UnanchoredRegex] performed by method ArrowAssoc in scala.Predef.
    Definition Classes
    ArrowAssoc
    Annotations
    @inline()
  5. final def ==(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  6. def anchored: Regex

    Definition Classes
    Regex
  7. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  8. def clone(): AnyRef

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  9. def ensuring(cond: (UnanchoredRegex) ⇒ Boolean, msg: ⇒ Any): UnanchoredRegex

    Implicit information
    This member is added by an implicit conversion from UnanchoredRegex to Ensuring[UnanchoredRegex] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  10. def ensuring(cond: (UnanchoredRegex) ⇒ Boolean): UnanchoredRegex

    Implicit information
    This member is added by an implicit conversion from UnanchoredRegex to Ensuring[UnanchoredRegex] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  11. def ensuring(cond: Boolean, msg: ⇒ Any): UnanchoredRegex

    Implicit information
    This member is added by an implicit conversion from UnanchoredRegex to Ensuring[UnanchoredRegex] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  12. def ensuring(cond: Boolean): UnanchoredRegex

    Implicit information
    This member is added by an implicit conversion from UnanchoredRegex to Ensuring[UnanchoredRegex] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  13. final def eq(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  14. def equals(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  15. def finalize(): Unit

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  16. def findAllIn(source: CharSequence): MatchIterator

    Return all matches of this regexp in given character sequence as a scala.util.matching.Regex.MatchIterator, which is a special scala.collection.Iterator that returns the matched strings, but can also be converted into a normal iterator that returns objects of type scala.util.matching.Regex.Match that can be queried for data such as the text that precedes the match, subgroups, etc.

    Return all matches of this regexp in given character sequence as a scala.util.matching.Regex.MatchIterator, which is a special scala.collection.Iterator that returns the matched strings, but can also be converted into a normal iterator that returns objects of type scala.util.matching.Regex.Match that can be queried for data such as the text that precedes the match, subgroups, etc.

    Attempting to retrieve information about a match before initializing the iterator can result in java.lang.IllegalStateExceptions. See scala.util.matching.Regex.MatchIterator for details.

    source

    The text to match against.

    returns

    A scala.util.matching.Regex.MatchIterator of all matches.

    Definition Classes
    Regex
    Example:
    1. for (words <- """\w+""".r findAllIn "A simple example.") yield words
  17. def findAllMatchIn(source: CharSequence): Iterator[Match]

    Return all matches of this regexp in given character sequence as a scala.collection.Iterator of scala.util.matching.Regex.Match.

    Return all matches of this regexp in given character sequence as a scala.collection.Iterator of scala.util.matching.Regex.Match.

    source

    The text to match against.

    returns

    A scala.collection.Iterator of scala.util.matching.Regex.Match for all matches.

    Definition Classes
    Regex
    Example:
    1. for (words <- """\w+""".r findAllMatchIn "A simple example.") yield words.start
  18. def findFirstIn(source: CharSequence): Option[String]

    Return optionally first matching string of this regexp in given character sequence, or None if it does not exist.

    Return optionally first matching string of this regexp in given character sequence, or None if it does not exist.

    source

    The text to match against.

    returns

    An scala.Option of the first matching string in the text.

    Definition Classes
    Regex
    Example:
    1. """\w+""".r findFirstIn "A simple example." foreach println // prints "A"
  19. def findFirstMatchIn(source: CharSequence): Option[Match]

    Return optionally first match of this regexp in given character sequence, or None if it does not exist.

    Return optionally first match of this regexp in given character sequence, or None if it does not exist.

    The main difference between this method and findFirstIn is that the (optional) return type for this is scala.util.matching.Regex.Match, through which more data can be obtained about the match, such as the strings that precede and follow it, or subgroups.

    source

    The text to match against.

    returns

    A scala.Option of scala.util.matching.Regex.Match of the first matching string in the text.

    Definition Classes
    Regex
    Example:
    1. ("""[a-z]""".r findFirstMatchIn "A simple example.") map (_.start) // returns Some(2), the index of the first match in the text
  20. def findPrefixMatchOf(source: CharSequence): Option[Match]

    Return optionally match of this regexp at the beginning of the given character sequence, or None if regexp matches no prefix of the character sequence.

    Return optionally match of this regexp at the beginning of the given character sequence, or None if regexp matches no prefix of the character sequence.

    The main difference from this method to findFirstMatchIn is that this method will not return any matches that do not begin at the start of the text being matched against.

    source

    The text to match against.

    returns

    A scala.Option of the scala.util.matching.Regex.Match of the matched string.

    Definition Classes
    Regex
    Example:
    1. """\w+""".r findPrefixMatchOf "A simple example." map (_.after) // returns Some(" simple example.")
  21. def findPrefixOf(source: CharSequence): Option[String]

    Return optionally match of this regexp at the beginning of the given character sequence, or None if regexp matches no prefix of the character sequence.

    Return optionally match of this regexp at the beginning of the given character sequence, or None if regexp matches no prefix of the character sequence.

    The main difference from this method to findFirstIn is that this method will not return any matches that do not begin at the start of the text being matched against.

    source

    The text to match against.

    returns

    A scala.Option of the matched prefix.

    Definition Classes
    Regex
    Example:
    1. """[a-z]""".r findPrefixOf "A simple example." // returns None, since the text does not begin with a lowercase letter
  22. def formatted(fmtstr: String): String

    Returns string formatted according to given format string.

    Returns string formatted according to given format string. Format strings are as for String.format (@see java.lang.String.format).

    Implicit information
    This member is added by an implicit conversion from UnanchoredRegex to StringFormat[UnanchoredRegex] performed by method StringFormat in scala.Predef.
    Definition Classes
    StringFormat
    Annotations
    @inline()
  23. final def getClass(): Class[_]

    Definition Classes
    AnyRef → Any
  24. def hashCode(): Int

    Definition Classes
    AnyRef → Any
  25. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  26. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  27. final def notify(): Unit

    Definition Classes
    AnyRef
  28. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  29. val pattern: Pattern

    The compiled pattern

    The compiled pattern

    Definition Classes
    Regex
  30. def regex: String

    Definition Classes
    Regex
  31. def replaceAllIn(target: CharSequence, replacer: (Match) ⇒ String): String

    Replaces all matches using a replacer function.

    Replaces all matches using a replacer function. The replacer function takes a scala.util.matching.Regex.Match so that extra information can be obtained from the match. For example:

    import scala.util.matching.Regex
    val datePattern = new Regex("""(\d\d\d\d)-(\d\d)-(\d\d)""", "year", "month", "day")
    val text = "From 2011-07-15 to 2011-07-17"
    val repl = datePattern replaceAllIn (text, m => m.group("month")+"/"+m.group("day"))

    In the replacement String, a dollar sign ($) followed by a number will be interpreted as a reference to a group in the matched pattern, with numbers 1 through 9 corresponding to the first nine groups, and 0 standing for the whole match. Any other character is an error. The backslash (\) character will be interpreted as an escape character, and can be used to escape the dollar sign. One can use scala.util.matching.Regex's quoteReplacement to automatically escape these characters.

    target

    The string to match.

    replacer

    The function which maps a match to another string.

    returns

    The target string after replacements.

    Definition Classes
    Regex
  32. def replaceAllIn(target: CharSequence, replacement: String): String

    Replaces all matches by a string.

    Replaces all matches by a string.

    In the replacement String, a dollar sign ($) followed by a number will be interpreted as a reference to a group in the matched pattern, with numbers 1 through 9 corresponding to the first nine groups, and 0 standing for the whole match. Any other character is an error. The backslash (\) character will be interpreted as an escape character, and can be used to escape the dollar sign. One can use scala.util.matching.Regex's quoteReplacement to automatically escape these characters.

    target

    The string to match

    replacement

    The string that will replace each match

    returns

    The resulting string

    Definition Classes
    Regex
    Example:
    1. """\d+""".r replaceAllIn ("July 15", "") // returns "July "
  33. def replaceFirstIn(target: CharSequence, replacement: String): String

    Replaces the first match by a string.

    Replaces the first match by a string.

    In the replacement String, a dollar sign ($) followed by a number will be interpreted as a reference to a group in the matched pattern, with numbers 1 through 9 corresponding to the first nine groups, and 0 standing for the whole match. Any other character is an error. The backslash (\) character will be interpreted as an escape character, and can be used to escape the dollar sign. One can use scala.util.matching.Regex's quoteReplacement to automatically escape these characters.

    target

    The string to match

    replacement

    The string that will replace the match

    returns

    The resulting string

    Definition Classes
    Regex
  34. def replaceSomeIn(target: CharSequence, replacer: (Match) ⇒ Option[String]): String

    Replaces some of the matches using a replacer function that returns an scala.Option.

    Replaces some of the matches using a replacer function that returns an scala.Option. The replacer function takes a scala.util.matching.Regex.Match so that extra information can be btained from the match. For example:

    import scala.util.matching.Regex._
    
    val map = Map("x" -> "a var", "y" -> """some $ and \ signs""")
    val text = "A text with variables %x, %y and %z."
    val varPattern = """%(\w+)""".r
    val mapper = (m: Match) => map get (m group 1) map (quoteReplacement(_))
    val repl = varPattern replaceSomeIn (text, mapper)

    In the replacement String, a dollar sign ($) followed by a number will be interpreted as a reference to a group in the matched pattern, with numbers 1 through 9 corresponding to the first nine groups, and 0 standing for the whole match. Any other character is an error. The backslash (\) character will be interpreted as an escape character, and can be used to escape the dollar sign. One can use scala.util.matching.Regex's quoteReplacement to automatically escape these characters.

    target

    The string to match.

    replacer

    The function which optionally maps a match to another string.

    returns

    The target string after replacements.

    Definition Classes
    Regex
  35. def runMatcher(m: Matcher): Boolean

    Attributes
    protected
    Definition Classes
    UnanchoredRegexRegex
  36. def split(toSplit: CharSequence): Array[String]

    Splits the provided character sequence around matches of this regexp.

    Splits the provided character sequence around matches of this regexp.

    toSplit

    The character sequence to split

    returns

    The array of strings computed by splitting the input around matches of this regexp

    Definition Classes
    Regex
  37. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  38. def toString(): String

    The string defining the regular expression

    The string defining the regular expression

    Definition Classes
    Regex → AnyRef → Any
  39. def unanchored: UnanchoredRegex

    Create a new Regex with the same pattern, but no requirement that the entire String matches in extractor patterns.

    Create a new Regex with the same pattern, but no requirement that the entire String matches in extractor patterns. For instance, the strings shown below lead to successful matches, where they would not otherwise.

    val dateP1 = """(\d\d\d\d)-(\d\d)-(\d\d)""".r.unanchored
    
    val dateP1(year, month, day) = "Date 2011-07-15"
    
    val copyright: String = "Date of this document: 2011-07-15" match {
      case dateP1(year, month, day) => "Copyright "+year
      case _                        => "No copyright"
    }
    returns

    The new unanchored regex

    Definition Classes
    UnanchoredRegexRegex
  40. def unapplySeq(m: Match): Option[List[String]]

    Tries to match on a scala.util.matching.Regex.Match.

    Tries to match on a scala.util.matching.Regex.Match. A previously failed match results in None. If a successful match was made against the current pattern, then that result is used. Otherwise, this Regex is applied to the previously matched input, and the result of that match is used.

    Definition Classes
    Regex
  41. def unapplySeq(c: Char): Option[List[Char]]

    Tries to match the String representation of a scala.Char.

    Tries to match the String representation of a scala.Char. If the match succeeds, the result is the first matching group if any groups are defined, or an empty Sequence otherwise.

    For example:

    val cat = "cat"
    // the case must consume the group to match
    val r = """(\p{Lower})""".r
    cat(0) match { case r(x) => true }
    cat(0) match { case r(_) => true }
    cat(0) match { case r(_*) => true }
    cat(0) match { case r() => true }     // no match
    
    // there is no group to extract
    val r = """\p{Lower}""".r
    cat(0) match { case r(x) => true }    // no match
    cat(0) match { case r(_) => true }    // no match
    cat(0) match { case r(_*) => true }   // matches
    cat(0) match { case r() => true }     // matches
    
    // even if there are multiple groups, only one is returned
    val r = """((.))""".r
    cat(0) match { case r(_) => true }    // matches
    cat(0) match { case r(_,_) => true }  // no match
    c

    The Char to match

    returns

    The match

    Definition Classes
    Regex
  42. def unapplySeq(s: CharSequence): Option[List[String]]

    Tries to match a java.lang.CharSequence.

    Tries to match a java.lang.CharSequence. If the match succeeds, the result is a list of the matching groups (or a null element if a group did not match any input). If the pattern specifies no groups, then the result will be an empty list on a successful match.

    This method attempts to match the entire input by default; to find the next matching subsequence, use an unanchored Regex.

    For example:

    val p1 = "ab*c".r
    val p1Matches = "abbbc" match {
      case p1() => true
      case _    => false
    }
    val p2 = "a(b*)c".r
    val numberOfB = "abbbc" match {
      case p2(b) => Some(b.length)
      case _     => None
    }
    val p3 = "b*".r.unanchored
    val p3Matches = "abbbc" match {
      case p3() => true
      case _    => false
    }
    s

    The string to match

    returns

    The matches

    Definition Classes
    Regex
  43. final def wait(): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  44. final def wait(arg0: Long, arg1: Int): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  45. final def wait(arg0: Long): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  46. def [B](y: B): (UnanchoredRegex, B)

    Implicit information
    This member is added by an implicit conversion from UnanchoredRegex to ArrowAssoc[UnanchoredRegex] performed by method ArrowAssoc in scala.Predef.
    Definition Classes
    ArrowAssoc

Deprecated Value Members

  1. def unapplySeq(target: Any): Option[List[String]]

    Tries to match target.

    Tries to match target.

    target

    The string to match

    returns

    The matches

    Definition Classes
    Regex
    Annotations
    @deprecated
    Deprecated

    (Since version 2.11.0) Extracting a match result from anything but a CharSequence or Match is deprecated

Inherited from Regex

Inherited from Serializable

Inherited from java.io.Serializable

Inherited from AnyRef

Inherited from Any

Inherited by implicit conversion any2stringadd from UnanchoredRegex to any2stringadd[UnanchoredRegex]

Inherited by implicit conversion StringFormat from UnanchoredRegex to StringFormat[UnanchoredRegex]

Inherited by implicit conversion Ensuring from UnanchoredRegex to Ensuring[UnanchoredRegex]

Inherited by implicit conversion ArrowAssoc from UnanchoredRegex to ArrowAssoc[UnanchoredRegex]

Ungrouped