TechnologiesFoundation, System & Concurrency

RegexBuilder

iOSmacOStvOSwatchOSvisionOS

RegexBuilder provides a result-builder DSL for composing Swift regular expressions declaratively, assembling patterns from character classes, alternations, and captures instead of from a literal string. You build a pattern by combining components such as CharacterClass and Anchor, expressing repetition with One, OneOrMore, ZeroOrMore, Optionally, and Repeat, and choosing between alternatives with ChoiceOf. Capture and TryCapture extract matched substrings, while Reference, Lookahead, NegativeLookahead, and Local give you backreferences and zero-width matching for more precise patterns.

Matching Elements 2

The building blocks that match characters and positions within a pattern.

  • St
    CharacterClassiOS 16.0+
    A class of characters that match in a regex.
  • St
    AnchoriOS 16.0+
    A regex component that matches a specific condition at a particular position

Quantifiers 5

Components that express how many times a subpattern should repeat.

  • St
    OneiOS 16.0+
    A regex component that matches exactly one occurrence of its underlying
  • St
    OneOrMoreiOS 16.0+
    A regex component that matches one or more occurrences of its underlying
  • St
    ZeroOrMoreiOS 16.0+
    A regex component that matches zero or more occurrences of its underlying
  • St
    OptionallyiOS 16.0+
    A regex component that matches zero or one occurrences of its underlying
  • St
    RepeatiOS 16.0+
    A regex component that matches a selectable number of occurrences of its

Alternation 1

A component for matching one of several alternative subpatterns.

  • St
    ChoiceOfiOS 16.0+
    A regex component that chooses exactly one of its constituent regex

Captures and References 3

Components that extract matched substrings and refer to them elsewhere in a pattern.

  • St
    CaptureiOS 16.0+
    A regex component that saves the matched substring, or a transformed result,
  • St
    TryCaptureiOS 16.0+
    A regex component that attempts to transform a matched substring, saving
  • St
    ReferenceiOS 16.0+
    A reference to a captured portion of a regular expression.

Lookahead and Scoping 3

Zero-width assertions and scoped matching that constrain a pattern without consuming input.

  • St
    LookaheadiOS 16.0+
    A regex component that allows a match to continue only if its contents
  • St
    NegativeLookaheadiOS 16.0+
    A regex component that allows a match to continue only if its contents
  • St
    LocaliOS 16.0+
    A regex component that represents an atomic group.

Structures 1

  • St
    AlternationBuilderiOS 16.0+
    A custom parameter attribute that constructs regular expression alternations

Enumerations 1

  • En
    RegexComponentBuilderiOS 16.0+
    A custom parameter attribute that constructs regular expressions from

Extends 9

RegexComponentBidirectionalCollectionRangeReplaceableCollectionStringProtocolRegexStringSubstringCharacterUnicode
← Foundation, System & Concurrency