Match
The result of matching a regular expression against a string.
- iOS
- 16.0+
- macOS
- 13.0+
- tvOS
- 16.0+
- watchOS
- 9.0+
@dynamicMemberLookup struct Match
A Match
forwards API to the Output
generic parameter, providing direct access to captures.
The result of matching a regular expression against a string.
@dynamicMemberLookup struct Match
A Match
forwards API to the Output
generic parameter, providing direct access to captures.
import _StringProcessing
struct Regex<Output>
A regular expression.
init(_ pattern: String, as outputType: Output.Type = Output.self) throws
Creates a regular expression from the given string, using the specified capture type.
init?(_ regex: Regex<AnyRegexOutput>, as outputType: Output.Type = Output.self)
Creates a regular expression with a strongly-typed capture list from the given regular expression.
init(verbatim verbatimString: String)
Creates a regular expression that matches the given string exactly, as though every metacharacter in it was escaped.
var regex: Regex<Output> { get }
func anchorsMatchLineEndings(_ matchLineEndings: Bool = true) -> Regex<Regex<Output>.RegexOutput>
Returns a regular expression where the start and end of input anchors (^
and $
) also match against the start and end of a line.
func asciiOnlyCharacterClasses(_ useASCII: Bool = true) -> Regex<Regex<Output>.RegexOutput>
Returns a regular expression that matches only ASCII characters when matching character classes.
func asciiOnlyDigits(_ useASCII: Bool = true) -> Regex<Regex<Output>.RegexOutput>
Returns a regular expression that matches only ASCII characters as digits.
func asciiOnlyWhitespace(_ useASCII: Bool = true) -> Regex<Regex<Output>.RegexOutput>
Returns a regular expression that matches only ASCII characters as space characters.
func asciiOnlyWordCharacters(_ useASCII: Bool = true) -> Regex<Regex<Output>.RegexOutput>
Returns a regular expression that matches only ASCII characters as word characters.
func contains(captureNamed name: String) -> Bool
Returns a Boolean value indicating whether a named capture with the given name exists.
func dotMatchesNewlines(_ dotMatchesNewlines: Bool = true) -> Regex<Regex<Output>.RegexOutput>
Returns a regular expression where the “any” metacharacter (.
) also matches against the start and end of a line.
func firstMatch(in string: String) throws -> Regex<Output>.Match?
Returns the first match for this regex found in the given string.
func firstMatch(in string: Substring) throws -> Regex<Output>.Match?
Returns the first match for this regex found in the given substring.
func ignoresCase(_ ignoresCase: Bool = true) -> Regex<Regex<Output>.RegexOutput>
Returns a regular expression that ignores case when matching.
func matchingSemantics(_ semanticLevel: RegexSemanticLevel) -> Regex<Regex<Output>.RegexOutput>
Returns a regular expression that matches with the specified semantic level.
func prefixMatch(in string: String) throws -> Regex<Output>.Match?
Returns a match if this regex matches the given string at its start.
func prefixMatch(in string: Substring) throws -> Regex<Output>.Match?
Returns a match if this regex matches the given substring at its start.
func repetitionBehavior(_ behavior: RegexRepetitionBehavior) -> Regex<Regex<Output>.RegexOutput>
Returns a regular expression where quantifiers use the specified behavior by default.
func wholeMatch(in string: String) throws -> Regex<Output>.Match?
Returns a match if this regex matches the given string in its entirety.
func wholeMatch(in string: Substring) throws -> Regex<Output>.Match?
Returns a match if this regex matches the given substring in its entirety.
func wordBoundaryKind(_ wordBoundaryKind: RegexWordBoundaryKind) -> Regex<Regex<Output>.RegexOutput>
Returns a regular expression that uses the specified word boundary algorithm.
var output: Output { get }
The output produced from the match operation.
let range: Range<String.Index>
The range of the overall match.
subscript<Capture>(id: ReferenceID) -> Capture { get }
subscript<T>(dynamicMember keyPath: KeyPath<Output, T>) -> T { get }
Accesses a capture by its name or number.
struct AnyRegexOutput
The type-erased, dynamic output of a regular expression match.
init<OtherOutput>(_ match: Regex<OtherOutput>.Match)
Creates a regular expression match with a dynamic capture list from the given match.
subscript(name: String) -> AnyRegexOutput.Element? { get }
Accesses the capture with the specified name, if a capture with that name exists.
import RegexBuilder
subscript<Capture>(reference: Reference<Capture>) -> Capture { get }
Accesses this match’s capture by the given reference.