Provides information about a succesful match.
This class provides methods to access the details of a match.
A class to step through a sequence of regex matches.
A class to step through a sequence of regex matches.
All methods inherited from scala.util.matching.Regex.MatchData will throw
a java.lang.IllegalStateException until the matcher is initialized. The
matcher can be initialized by calling hasNext
or next()
or causing these
methods to be called, such as by invoking toString
or iterating through
the iterator's elements.
java.util.regex.Matcher
An extractor object that yields the groups in the match.
An extractor object that yields the groups in the match. Using an extractor rather than the original regex avoids recomputing the match.
import scala.util.matching.Regex.Groups val datePattern = """(\d\d\d\d)-(\d\d)-(\d\d)""".r val text = "The doc spree happened on 2011-07-15." val day = datePattern replaceAllIn(text, _ match { case Groups(year, month, day) => month+"/"+day })
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 })
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.
List("US$", "CAN$").map(Regex.quote).mkString("|").r
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.
The string one wishes to use as literal replacement.
A string that can be used to replace matches with text
.
"CURRENCY".r.replaceAllIn(input, Regex quoteReplacement "US$")
This object defines inner classes that describe regex matches and helper objects.