diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/library/scala/util/matching/Regex.scala | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/library/scala/util/matching/Regex.scala b/src/library/scala/util/matching/Regex.scala index 8d135ecf02..8eac0a2520 100644 --- a/src/library/scala/util/matching/Regex.scala +++ b/src/library/scala/util/matching/Regex.scala @@ -205,6 +205,20 @@ class Regex private[matching](val pattern: Pattern, groupNames: String*) extends else if (m.matcher.pattern == this.pattern) Some(1 to m.groupCount map m.group) else unapplySeq(m.matched) + /** Tries to match target. + * @param target The string to match + * @return The matches + */ + @deprecated("Extracting a match result from anything but a CharSequence or Match is deprecated", "2.11.0") + def unapplySeq(target: Any): Option[List[String]] = target match { + case s: CharSequence => + val m = pattern matcher s + if (runMatcher(m)) Some((1 to m.groupCount).toList map m.group) + else None + case m: Match => unapplySeq(m.matched) + case _ => None + } + // @see UnanchoredRegex protected def runMatcher(m: Matcher) = m.matches() |