Movatterモバイル変換


[0]ホーム

URL:


Scala 3
3.7.4
LearnInstallPlaygroundFind A LibraryCommunityBlog
Scala 3
LearnInstallPlaygroundFind A LibraryCommunityBlog
DocsAPI
Generated with
Copyright (c) 2002-2025, LAMP/EPFL
Copyright (c) 2002-2025, LAMP/EPFL
Scala 3/scala/scala.util/scala.util.matching/Regex

Regex

scala.util.matching.Regex
See theRegex companion class
objectRegex

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

Attributes

Companion
class
Source
Regex.scala
Graph
Supertypes
classObject
traitMatchable
classAny
Self type
Regex.type

Members list

Type members

Classlikes

objectGroups

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 originalRegex ensures that the match is not recomputed.

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

Attributes

Source
Regex.scala
Supertypes
classObject
traitMatchable
classAny
Self type
Groups.type
classMatch(valsource:CharSequence,valmatcher:Matcher,_groupNames:Seq[String]) extendsMatchData

Provides information about a successful match.

Provides information about a successful match.

Attributes

Companion
object
Source
Regex.scala
Supertypes
traitMatchData
classObject
traitMatchable
classAny
objectMatch

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 })

Attributes

Companion
class
Source
Regex.scala
Supertypes
classObject
traitMatchable
classAny
Self type
Match.type

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

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

Attributes

Source
Regex.scala
Supertypes
classObject
traitMatchable
classAny
Known subtypes
classMatch
classMatchIterator(valsource:CharSequence,valregex:Regex,val_groupNames:Seq[String]) extendsAbstractIterator[String],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 callinghasNext ornext.

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

Attributes

See also
Source
Regex.scala
Supertypes
Self type

Value members

Concrete methods

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.

Attributes

Example

List("US$", "CAN$").map(Regex.quote).mkString("|").r
Source
Regex.scala

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.

Value parameters

text

The string one wishes to use as literal replacement.

Attributes

Returns

A string that can be used to replace matches withtext.

Example

"CURRENCY".r.replaceAllIn(input, Regex quoteReplacement "US$")
Source
Regex.scala
In this article
Generated with
Copyright (c) 2002-2025, LAMP/EPFL
Copyright (c) 2002-2025, LAMP/EPFL

[8]ページ先頭

©2009-2025 Movatter.jp