<!--
{
  "availability" : [
    "iOS: 16.0.0 -",
    "iPadOS: 16.0.0 -",
    "macCatalyst: 16.0.0 -",
    "macOS: 13.0.0 -",
    "tvOS: 16.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 9.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/RegexComponent",
  "metadataVersion" : "0.1.0",
  "role" : "Protocol",
  "symbol" : {
    "kind" : "Protocol",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:17_StringProcessing14RegexComponentP"
  },
  "title" : "RegexComponent"
}
-->

# RegexComponent

A type that represents a regular expression.

```
protocol RegexComponent<RegexOutput>
```

## Overview

You can use types that conform to `RegexComponent` as parameters to string
searching operations and inside `RegexBuilder` closures.

## Topics

### Creating a regex component

[`init(_:_:)`](/documentation/Swift/RegexComponent/init(_:_:))

Creates a character class that combines the given classes in a union.

### Getting a regex from a component

[`regex`](/documentation/Swift/RegexComponent/regex)

The regular expression represented by this component.

### Matching substring sequences

[`anyOf(_:)`](/documentation/Swift/RegexComponent/anyOf(_:)-3pexl)

Returns a character class that matches any Unicode scalar in the given
sequence.

[`anyOf(_:)`](/documentation/Swift/RegexComponent/anyOf(_:)-4xgea)

Returns a character class that matches any character in the given string
or sequence.

[`any`](/documentation/Swift/RegexComponent/any)

A character class that matches any element.

[`anyGraphemeCluster`](/documentation/Swift/RegexComponent/anyGraphemeCluster)

A character class that matches any single `Character`, or extended
grapheme cluster, regardless of the current semantic level.

[`anyNonNewline`](/documentation/Swift/RegexComponent/anyNonNewline)

A character class that matches any element that isn’t a newline.

[`digit`](/documentation/Swift/RegexComponent/digit)

A character class that matches any digit.

[`hexDigit`](/documentation/Swift/RegexComponent/hexDigit)

A character class that matches any hexadecimal digit.

[`word`](/documentation/Swift/RegexComponent/word)

A character class that matches any element that is a “word character”.

### Matching whitespace and line endings

[`horizontalWhitespace`](/documentation/Swift/RegexComponent/horizontalWhitespace)

A character class that matches any element that is classified as
horizontal whitespace.

[`newlineSequence`](/documentation/Swift/RegexComponent/newlineSequence)

A character class that matches any newline sequence.

[`verticalWhitespace`](/documentation/Swift/RegexComponent/verticalWhitespace)

A character class that matches any element that is classified as
vertical whitespace.

[`whitespace`](/documentation/Swift/RegexComponent/whitespace)

A character class that matches any element that is classified as
whitespace.

### Matching dates and times

[`date(_:locale:timeZone:calendar:)`](/documentation/Swift/RegexComponent/date(_:locale:timeZone:calendar:))

Creates a regex component that matches a localized date string formatted in accordance with a style, capturing it as a Foundation date.

[`date(format:locale:timeZone:calendar:twoDigitStartDate:)`](/documentation/Swift/RegexComponent/date(format:locale:timeZone:calendar:twoDigitStartDate:))

Creates a regex component that matches a localized date string formatted in accordance with a format string, capturing it as a Foundation date.

[`dateTime(date:time:locale:timeZone:calendar:)`](/documentation/Swift/RegexComponent/dateTime(date:time:locale:timeZone:calendar:))

Creates a regex component that matches a localized date and time string, capturing it as a Foundation date.

[`iso8601`](/documentation/Swift/RegexComponent/iso8601)

A regex component that matches a default ISO 8601-formatted date string, capturing it as a Foundation date.

[`iso8601Date(timeZone:dateSeparator:)`](/documentation/Swift/RegexComponent/iso8601Date(timeZone:dateSeparator:))

Creates a regex component that matches an ISO 8601-formatted date string, capturing it as a Foundation date in the specified time zone.

[`iso8601(timeZone:includingFractionalSeconds:dateSeparator:dateTimeSeparator:timeSeparator:)`](/documentation/Swift/RegexComponent/iso8601(timeZone:includingFractionalSeconds:dateSeparator:dateTimeSeparator:timeSeparator:))

Creates a regex component that matches an ISO 8601-formatted date string, capturing the matched substring as a Foundation date in the specified time zone.

[`iso8601WithTimeZone(includingFractionalSeconds:dateSeparator:dateTimeSeparator:timeSeparator:timeZoneSeparator:)`](/documentation/Swift/RegexComponent/iso8601WithTimeZone(includingFractionalSeconds:dateSeparator:dateTimeSeparator:timeSeparator:timeZoneSeparator:))

Creates a regex component that matches an ISO 8601-formatted date string that includes a time zone component, capturing the matched substring as a Foundation date.

### Matching numeric formats

[`localizedInteger(locale:)`](/documentation/Swift/RegexComponent/localizedInteger(locale:))

Creates a regex component that matches a localized numeric string, capturing it as an integer value.

[`localizedDouble(locale:)`](/documentation/Swift/RegexComponent/localizedDouble(locale:))

Creates a regex component that matches a localized numeric string, capturing it as a double-precision floating-point value.

[`localizedDecimal(locale:)`](/documentation/Swift/RegexComponent/localizedDecimal(locale:))

Creates a regex component that matches a localized decimal string, capturing it as a Foundation decimal.

[`localizedCurrency(code:locale:)`](/documentation/Swift/RegexComponent/localizedCurrency(code:locale:))

Creates a regex component that matches a localized currency string, capturing it as a decimal value.

[`localizedIntegerCurrency(code:locale:)`](/documentation/Swift/RegexComponent/localizedIntegerCurrency(code:locale:))

Creates a regex component that matches a localized currency string, capturing it as an integer value.

[`localizedIntegerPercentage(locale:)`](/documentation/Swift/RegexComponent/localizedIntegerPercentage(locale:))

Creates a regex component that matches a localized percentage string, capturing it as a double-precision floating-point value.

[`localizedDoublePercentage(locale:)`](/documentation/Swift/RegexComponent/localizedDoublePercentage(locale:))

Creates a regex component that matches a localized percentage string, capturing it as a double-precision floating-point value.

### Matching URLs

[`url(scheme:user:password:host:port:path:query:fragment:)`](/documentation/Swift/RegexComponent/url(scheme:user:password:host:port:path:query:fragment:))

Creates a regex component that matches a URL substring, capturing it as a Foundation URL.

### Supporting types

[`RegexOutput`](/documentation/Swift/RegexComponent/RegexOutput)

The output type for this regular expression.

[`RegexComponent.DateStyle`](/documentation/Swift/RegexComponent/DateStyle)

A type alias to use when matching date components in a regular expression.

[`RegexComponent.TimeStyle`](/documentation/Swift/RegexComponent/TimeStyle)

A type alias to use when matching time components in a regular expression.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)