@@ -61,7 +61,7 @@ public struct AnyRegexOutput {
61
61
62
62
@available ( SwiftStdlib 5 . 7 , * )
63
63
extension AnyRegexOutput {
64
- /// Creates a type-erased regex output from an existing output .
64
+ /// Creates a type-erased regex output from an existing match .
65
65
///
66
66
/// Use this initializer to fit a regex with strongly typed captures into the
67
67
/// use site of a dynamic regex, like one that was created from a string.
@@ -186,10 +186,12 @@ extension Regex where Output == AnyRegexOutput {
186
186
187
187
@available ( SwiftStdlib 5 . 7 , * )
188
188
extension Regex {
189
- /// Creates a strongly-typed regex from a dynamic regex.
189
+ /// Creates a strongly-typed regex from a dynamic regex, i.e. one created
190
+ /// from a string.
190
191
///
191
192
/// Use this initializer to create a strongly typed regex from
192
- /// one that was created from a string.
193
+ /// one that was created from a string. Returns `nil` if the types
194
+ /// don't match.
193
195
public init ? ( _ dynamic: Regex < AnyRegexOutput > ) {
194
196
self . init ( node: dynamic. root)
195
197
guard self . _verifyType ( ) else {
@@ -249,3 +251,12 @@ extension AnyRegexOutput.ElementRepresentation {
249
251
)
250
252
}
251
253
}
254
+
255
+ @available ( SwiftStdlib 5 . 7 , * )
256
+ extension Regex {
257
+ /// Produces a regex that matches `verbatim` exactly, as though every
258
+ /// metacharacter in it was escaped.
259
+ public init ( verbatim: String ) {
260
+ self . init ( node: . quotedLiteral( verbatim) )
261
+ }
262
+ }
0 commit comments