File tree Expand file tree Collapse file tree 2 files changed +27
-0
lines changed
Sources/_StringProcessing/Regex Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -185,3 +185,15 @@ extension Regex {
185
185
self . init ( node: . quotedLiteral( string) )
186
186
}
187
187
}
188
+
189
+ @available ( SwiftStdlib 5 . 7 , * )
190
+ public func ~= < Output> ( regex: Regex < Output > , input: String ) -> Bool {
191
+ guard let _ = try ? regex. wholeMatch ( in: input) else { return false }
192
+ return true
193
+ }
194
+
195
+ @available ( SwiftStdlib 5 . 7 , * )
196
+ public func ~= < Output> ( regex: Regex < Output > , input: Substring ) -> Bool {
197
+ guard let _ = try ? regex. wholeMatch ( in: input) else { return false }
198
+ return true
199
+ }
Original file line number Diff line number Diff line change @@ -172,4 +172,19 @@ class RegexConsumerTests: XCTestCase {
172
172
s2. matches ( of: regex) . map ( \. 0 ) ,
173
173
[ " aa " ] )
174
174
}
175
+
176
+ func testSwitches( ) {
177
+ switch " abcde " {
178
+ case try ! Regex ( " a.*f " ) :
179
+ XCTFail ( )
180
+ case try ! Regex ( " abc " ) :
181
+ XCTFail ( )
182
+
183
+ case try ! Regex ( " a.*e " ) :
184
+ break // success
185
+
186
+ default :
187
+ XCTFail ( )
188
+ }
189
+ }
175
190
}
You can’t perform that action at this time.
0 commit comments