[swift-evolution] [Draft] Swift implementation Regex added
bknope at me.com
Mon Jul 25 11:55:25 CDT 2016
There has been talk on this list of adding a fully featured RegEx feature. It has been pushed back to a later release as the window for Swift 3 is closing
> On Jul 25, 2016, at 12:24 PM, Joshua Alvarado via swift-evolution <swift-evolution at swift.org> wrote:
> My first proposal so take it easy on me :) This is a draft so feedback is very welcome and any help. Thank you swiftys.
> Swift doesn’t have a native implementation of Regex which is included in many other languages. This proposal is a suggestion to introduce a native Regex type into Swift.
> Working with NSRegularExpression is not very swift like and it is lacking in ease of use. More motivation comes from also comes from one of the goals of swift with Swiftification of imported Objective-C APIs.
> *Proposed solution*
> Add a struct of Regex that can be used with the String type.
> Regex can be initialized with a String pattern of the Regex and have simple properties such as accessing the pattern and toString of the pattern.
> String to be extended for Regex support. Functions to add be:
> mutating func replace(regex: Regex, withString: String)
> search(regex: Regex) -> Character.Index
> match(regex: Regex) -> Match? // Match is another new type
> Match is a new type that can give more information on a regex match. Match will have properties such as numberOfMatches, components (the substring of matches in an array), and rangeOfMatch.
> *Impact on existing code*
> NSRegularExpression will stay and can still be used in combination, but a more swift like implementation will be out of the box in Swift.
> *Alternatives considered*
> Regex could be a protocol added to String for matching.
> swift-evolution mailing list
> swift-evolution at swift.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution