Skip to content

Commit 2c071be

Browse files
natecook1000hamishknight
authored andcommitted
Keep substring bounds when searching in Regex.wholeMatch
1 parent 69c375f commit 2c071be

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

Sources/_StringProcessing/Regex/Match.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ extension BidirectionalCollection where SubSequence == Substring {
164164
public func wholeMatch<R: RegexComponent>(
165165
of r: R
166166
) -> Regex<R.RegexOutput>.Match? {
167-
try? r.regex.wholeMatch(in: self[...].base)
167+
try? r.regex.wholeMatch(in: self[...])
168168
}
169169

170170
/// Checks for a match against the string, starting at its beginning.

Tests/RegexBuilderTests/AlgorithmsTests.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,16 @@ class AlgorithmsResultBuilderTests: XCTestCase {
170170
}
171171

172172
func testMatches() throws {
173+
do {
174+
let regex = Regex { OneOrMore(.any) }
175+
XCTAssertEqual("abc".wholeMatch(of: regex)!.0, "abc")
176+
XCTAssertEqual("abc".prefixMatch(of: regex)!.0, "abc")
177+
XCTAssertEqual("abc".firstMatch(of: regex)!.0, "abc")
178+
XCTAssertEqual("abc".suffix(1).wholeMatch(of: regex)!.0, "c")
179+
XCTAssertEqual("abc".suffix(1).prefixMatch(of: regex)!.0, "c")
180+
XCTAssertEqual("abc".suffix(1).firstMatch(of: regex)!.0, "c")
181+
}
182+
173183
let int = Capture(OneOrMore(.digit)) { Int($0)! }
174184

175185
// Test syntax

0 commit comments

Comments
 (0)