diff --git a/Sources/_StringProcessing/Regex/Match.swift b/Sources/_StringProcessing/Regex/Match.swift index e2c6e1a87..3a9f37b60 100644 --- a/Sources/_StringProcessing/Regex/Match.swift +++ b/Sources/_StringProcessing/Regex/Match.swift @@ -177,7 +177,7 @@ extension BidirectionalCollection where SubSequence == Substring { public func wholeMatch( of r: R ) -> Regex.Match? { - try? r.regex.wholeMatch(in: self[...].base) + try? r.regex.wholeMatch(in: self[...]) } /// Checks for a match against the string, starting at its beginning. diff --git a/Tests/RegexBuilderTests/AlgorithmsTests.swift b/Tests/RegexBuilderTests/AlgorithmsTests.swift index 4545e8b1f..def55bc17 100644 --- a/Tests/RegexBuilderTests/AlgorithmsTests.swift +++ b/Tests/RegexBuilderTests/AlgorithmsTests.swift @@ -229,6 +229,16 @@ class AlgorithmsResultBuilderTests: XCTestCase { } func testMatches() throws { + do { + let regex = Regex { OneOrMore(.any) } + XCTAssertEqual("abc".wholeMatch(of: regex)!.0, "abc") + XCTAssertEqual("abc".prefixMatch(of: regex)!.0, "abc") + XCTAssertEqual("abc".firstMatch(of: regex)!.0, "abc") + XCTAssertEqual("abc".suffix(1).wholeMatch(of: regex)!.0, "c") + XCTAssertEqual("abc".suffix(1).prefixMatch(of: regex)!.0, "c") + XCTAssertEqual("abc".suffix(1).firstMatch(of: regex)!.0, "c") + } + let int = Capture(OneOrMore(.digit)) { Int($0)! } // Test syntax