@@ -226,3 +226,64 @@ public struct NegativeLookahead<Output>: _BuiltinRegexComponent {
226226 self . init ( _RegexFactory ( ) . negativeLookaheadNonCapturing ( component ( ) ) )
227227 }
228228}
229+
230+ /// A regex component that allows a match to continue only if its contents
231+ /// match at the given location.
232+ ///
233+ /// A lookbehind is a zero-length assertion that its included regex matches at
234+ /// a particular position. Lookbehinds do not advance the overall matching
235+ /// position in the input string — once a lookbehind succeeds, matching continues
236+ /// in the regex from the same position.
237+ @available ( SwiftStdlib 5 . 7 , * ) // TODO: How should this be gated?
238+ public struct Lookbehind < Output> : _BuiltinRegexComponent {
239+ public var regex : Regex < Output >
240+
241+ init ( _ regex: Regex < Output > ) {
242+ self . regex = regex
243+ }
244+
245+ /// Creates a lookbehind from the given regex component.
246+ public init < R: RegexComponent > (
247+ _ component: R
248+ ) where R. RegexOutput == Output {
249+ self . init ( _RegexFactory ( ) . lookbehindNonCapturing ( component) )
250+ }
251+
252+ /// Creates a lookbehind from the regex generated by the given builder closure.
253+ public init < R: RegexComponent > (
254+ @RegexComponentBuilder _ component: ( ) -> R
255+ ) where R. RegexOutput == Output {
256+ self . init ( _RegexFactory ( ) . lookbehindNonCapturing ( component ( ) ) )
257+ }
258+ }
259+
260+ /// A regex component that allows a match to continue only if its contents
261+ /// do not match at the given location.
262+ ///
263+ /// A negative lookbehind is a zero-length assertion that its included regex
264+ /// does not match at a particular position. Lookbehinds do not advance the
265+ /// overall matching position in the input string — once a lookbehind succeeds,
266+ /// matching continues in the regex from the same position.
267+ @available ( SwiftStdlib 5 . 7 , * ) // TODO: How should this be gated?
268+ public struct NegativeLookbehind < Output> : _BuiltinRegexComponent {
269+ public var regex : Regex < Output >
270+
271+ init ( _ regex: Regex < Output > ) {
272+ self . regex = regex
273+ }
274+
275+ /// Creates a negative lookbehind from the given regex component.
276+ public init < R: RegexComponent > (
277+ _ component: R
278+ ) where R. RegexOutput == Output {
279+ self . init ( _RegexFactory ( ) . negativeLookbehindNonCapturing ( component) )
280+ }
281+
282+ /// Creates a negative lookbehind from the regex generated by the given builder
283+ /// closure.
284+ public init < R: RegexComponent > (
285+ @RegexComponentBuilder _ component: ( ) -> R
286+ ) where R. RegexOutput == Output {
287+ self . init ( _RegexFactory ( ) . negativeLookbehindNonCapturing ( component ( ) ) )
288+ }
289+ }
0 commit comments