<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">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<div class=""><br class=""></div><div class="">Brandon</div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jul 25, 2016, at 12:24 PM, Joshua Alvarado via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><pre style="white-space: pre-wrap; background-color: rgb(255, 255, 255);" class=""><div style="margin: 0px; line-height: normal; font-family: Menlo; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;" class=""><span style="font-kerning: none" class="">My first proposal so take it easy on me :) This is a draft so feedback is very welcome and any help. Thank you swiftys.</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;" class=""><span style="font-kerning: none" class=""><br class=""></span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;" class=""><span style="font-kerning: none" class="">*Introduction*</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; min-height: 14px;" class=""><span style="font-kerning: none" class=""></span><br class=""></div><div style="margin: 0px; line-height: normal; font-family: Menlo; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;" class=""><span style="font-kerning: none" class="">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.&nbsp;</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; min-height: 14px;" class=""><span style="font-kerning: none" class=""></span><br class=""></div><div style="margin: 0px; line-height: normal; font-family: Menlo; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;" class=""><span style="font-kerning: none" class="">*Motivation*</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;" class=""><span style="font-kerning: none" class="">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.</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; min-height: 14px;" class=""><span style="font-kerning: none" class=""></span><br class=""></div><div style="margin: 0px; line-height: normal; font-family: Menlo; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;" class=""><span style="font-kerning: none" class="">*Proposed solution*</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; min-height: 14px;" class=""><span style="font-kerning: none" class=""></span><br class=""></div><div style="margin: 0px; line-height: normal; font-family: Menlo; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;" class=""><span style="font-kerning: none" class="">Add a struct of Regex that can be used with the String type.</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;" class=""><span style="font-kerning: none" class=""><br class=""></span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;" class=""><span style="font-kerning: none" class="">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.</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;" class=""><span style="font-kerning: none" class=""><br class=""></span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;" class=""><span style="font-kerning: none" class="">String to be extended for Regex support. Functions to add be:</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;" class=""><span style="font-kerning: none" class=""><br class=""></span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;" class=""><span style="font-kerning: none" class="">mutating func replace(regex: Regex, withString: String)</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;" class=""><span style="font-kerning: none" class="">search(regex: Regex) -&gt; Character.Index</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;" class=""><span style="font-kerning: none" class="">match(regex: Regex) -&gt; Match? // Match is another new type</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;" class=""><span style="font-kerning: none" class=""><br class=""></span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;" class=""><span style="font-kerning: none" class="">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.</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;" class=""><span style="font-kerning: none" class=""><br class=""></span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;" class=""><span style="font-kerning: none" class="">*Impact on existing code*</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;" class=""><span style="font-kerning: none" class="">NSRegularExpression will stay and can still be used in combination, but a more swift like implementation will be out of the box in Swift.</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;" class=""><span style="font-kerning: none" class=""><br class=""></span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;" class=""><span style="font-kerning: none" class="">*Alternatives considered*</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;" class=""><span style="font-kerning: none" class="">Regex could be a protocol added to String for matching.</span></div><div style="margin: 0px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; min-height: 14px;" class=""><span style="font-kerning: none" class=""></span><br class=""></div>
</pre></div>_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></div></body></html>