Regexes include lookaround assertions, which might look before or after the current search point. Additionally, some anchors will actually try to look at the surrounding context outside of the searched range, though there are modes and options to tweak this.
The main reason is that it's strictly more general to take a collection and range than a slice, especially if there's ever a need to look outside that range (e.g. some anchors mentioned above). Substring
does expose a .base
method to get the overall string, but it's a little cleaner and clearer for libraries to just have the range. E.g., Substring
can be mutated and that will change the value of base
, so trafficking in ranges for the lowest-level conformer interfaces is clearer.
Avoiding ARC is always a plus, obviously, but it's not as clear to me that it would make a difference here.