A regex component that matches a specific condition at a particular position
in an input string.
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.
Members (10)
get · iOS 16.0+
startOfLine
TypeScript
static get startOfLine(): Anchor
Swift declaration
static var startOfLine: Anchor { get }
An anchor that matches at the start of a line, including the start of
the input string.
This anchor is equivalent to `^` in regex syntax when the `m` option
has been enabled or `anchorsMatchLineEndings(true)` has been called.
For example, the following regexes are all equivalent:
- `Regex { Anchor.startOfLine }`
- `/(?m)^/` or `/(?m:^)/`
- `/^/.anchorsMatchLineEndings(true)`
get · iOS 16.0+
endOfSubject
TypeScript
static get endOfSubject(): Anchor
Swift declaration
static var endOfSubject: Anchor { get }
An anchor that matches at the end of the input string.
This anchor is equivalent to `\z` in regex syntax.
get · iOS 16.0+
wordBoundary
TypeScript
static get wordBoundary(): Anchor
Swift declaration
static var wordBoundary: Anchor { get }
An anchor that matches at a word boundary.
Word boundaries are identified using the Unicode default word boundary
algorithm by default. To specify a different word boundary algorithm,
use the `wordBoundaryKind(_:)` method.
This anchor is equivalent to `\b` in regex syntax.
get · iOS 16.0+
startOfSubject
TypeScript
static get startOfSubject(): Anchor
Swift declaration
static var startOfSubject: Anchor { get }
An anchor that matches at the start of the input string.
This anchor is equivalent to `\A` in regex syntax.
get · iOS 16.0+
textSegmentBoundary
TypeScript
static get textSegmentBoundary(): Anchor
Swift declaration
static var textSegmentBoundary: Anchor { get }
An anchor that matches at a grapheme cluster boundary.
This anchor is equivalent to `\y` in regex syntax.
get · iOS 16.0+
endOfSubjectBeforeNewline
TypeScript
static get endOfSubjectBeforeNewline(): Anchor
Swift declaration
static var endOfSubjectBeforeNewline: Anchor { get }
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.
This anchor is equivalent to `\Z` in regex syntax.
get · iOS 16.0+
firstMatchingPositionInSubject
TypeScript
static get firstMatchingPositionInSubject(): Anchor
Swift declaration
static var firstMatchingPositionInSubject: Anchor { get }
An anchor that matches at the first position of a match in the input
string.
get · iOS 16.0+
regex
TypeScript
get regex(): SDKHandle
Swift declaration
var regex: Regex<Substring> { get }
The regular expression represented by this component.
get · iOS 16.0+
inverted
TypeScript
get inverted(): Anchor
Swift declaration
var inverted: Anchor { get }
The inverse of this anchor, which matches at every position that this
anchor does not.
For the ``wordBoundary`` and ``textSegmentBoundary`` anchors, the inverted
version corresponds to `\B` and `\Y`, respectively.
get · iOS 16.0+
endOfLine
TypeScript
static get endOfLine(): Anchor
Swift declaration
static var endOfLine: Anchor { get }
An anchor that matches at the end of a line, including at the end of
the input string.
This anchor is equivalent to `$` in regex syntax when the `m` option
has been enabled or `anchorsMatchLineEndings(true)` has been called.
For example, the following regexes are all equivalent:
- `Regex { Anchor.endOfLine }`
- `/(?m)$/` or `/(?m:$)/`
- `/$/.anchorsMatchLineEndings(true)`