[Pitch] Regex-powered string processing algorithms

I think it would be unfortunate if the only way to spell this operation would be with the ~= operator. The (only?) other override of ~= that I could find in the stdlib is for Range, where it is effectively an alias for .contains(...). Would it make sense to add a Regex analogue of elementsEqual?

extension BidirectionalCollection where SubSequence == Substring {
  public func elementsEqual(_ other: some RegexComponent) -> Bool 
}

I'll admit that the naming is much less clear than for contains(_:) and starts(with:), but it is at least consistent. ~= could then be an alias for this.

Yours and @Karl 's arguments have convinced me that this is the right choice :slight_smile: .

:+1:

It would definitely be nice to make abstracting over composing regexes easier. With the current proposals, it's possible to compose regexes (which is already a huge improvement over what's available elsewhere). As I discovered above, putting this composition into a function is much harder! Your idea for regex literal interpolation looks like it might help with this?

2 Likes