<!--
{
  "availability" : [
    "iOS: 16.0.0 -",
    "iPadOS: 16.0.0 -",
    "macCatalyst: 16.0.0 -",
    "macOS: 13.0.0 -",
    "tvOS: 16.0.0 -",
    "visionOS: -",
    "watchOS: 9.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Swift",
  "identifier" : "/documentation/RegexBuilder/Anchor",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "RegexBuilder"
    ],
    "preciseIdentifier" : "s:12RegexBuilder6AnchorV"
  },
  "title" : "Anchor"
}
-->

# Anchor

A regex component that matches a specific condition at a particular position
in an input string.

```
struct Anchor
```

## Overview

You can use anchors to guarantee that a match only occurs at certain points
in an input string, such as at the beginning of the string or at the end of
a line.

## Topics

### Instance Properties

[`var inverted: Anchor`](/documentation/RegexBuilder/Anchor/inverted)

The inverse of this anchor, which matches at every position that this
anchor does not.

### Type Properties

[`static var endOfLine: Anchor`](/documentation/RegexBuilder/Anchor/endOfLine)

An anchor that matches at the end of a line, including at the end of
the input string.

[`static var endOfSubject: Anchor`](/documentation/RegexBuilder/Anchor/endOfSubject)

An anchor that matches at the end of the input string.

[`static var endOfSubjectBeforeNewline: Anchor`](/documentation/RegexBuilder/Anchor/endOfSubjectBeforeNewline)

An anchor that matches at the end of the input string or at the end of
the line immediately before the end of the string.

[`static var firstMatchingPositionInSubject: Anchor`](/documentation/RegexBuilder/Anchor/firstMatchingPositionInSubject)

An anchor that matches at the first position of a match in the input
string.

[`static var startOfLine: Anchor`](/documentation/RegexBuilder/Anchor/startOfLine)

An anchor that matches at the start of a line, including the start of
the input string.

[`static var startOfSubject: Anchor`](/documentation/RegexBuilder/Anchor/startOfSubject)

An anchor that matches at the start of the input string.

[`static var textSegmentBoundary: Anchor`](/documentation/RegexBuilder/Anchor/textSegmentBoundary)

An anchor that matches at a grapheme cluster boundary.

[`static var wordBoundary: Anchor`](/documentation/RegexBuilder/Anchor/wordBoundary)

An anchor that matches at a word boundary.

## Relationships

### Conforms To

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

[`Copyable`](/documentation/Swift/Copyable)

[`Escapable`](/documentation/Swift/Escapable)

---

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)