<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div><br><br>Sent from my iPad</div><div><br>On Jan 23, 2017, at 7:49 AM, Joshua Alvarado <<a href="mailto:alvaradojoshua0@gmail.com">alvaradojoshua0@gmail.com</a>> wrote:<br><br></div><blockquote type="cite"><div dir="ltr"><div>The strings proposal is a warm welcome to the Swift Language and I believe many developers are happy to see Strings become a priority. String processing may be one of the most common tasks for a developer day to day. That being said one thing in the proposal I believe is not correct is the leaving out regular expressions. </div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">"<span style="color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,'segoe ui',helvetica,arial,sans-serif,'apple color emoji','segoe ui emoji','segoe ui symbol';font-size:16px">Addressing regular expressions is out of scope for this proposal." </span></blockquote></div></blockquote><div><br></div>We shouldn't have said "this proposal," because it's a manifesto, not a proposal. Addressing Regexps in Swift proper <u>is</u> out of scope for Swift 4, because there's simply no time to design and add the necessary language features.<div><br><blockquote type="cite"><div dir="ltr"><div>Working with regular expressions in both Objective-c and Swift is a real pain. I don't believe that because NSRegularExpression exists is a good enough reason to leave it out of Swift 4 string improvements. NSRegularExpression is NOT easily retrofitted to strings. </div></div></blockquote><div><br></div>It should be easy to retrofit it to the pattern matching system so NSRegularExpression it works smoothly in Swift, but NSRegularExpression is outside the standard library so this is something to take up with the Foundation maintainers.</div><div><br><div><blockquote type="cite"><div><div dir="ltr"><div>Perl, ruby, javascript and many more programming languages have native easy to use regular expression functionality built in. <br></div><div><br></div><div>Examples:</div><div>Ruby:</div><div>/hey/ =~ 'hey what's up'</div><div>/world/.match('hello world')</div><div><br></div><div>Javascript:</div><div>'javascript regex'.search(/regex/)</div><div>'hello replace'.replace(/replace/, 'world')<br></div><div><br></div><div>Perl</div><div>$statement = "The quick brown fox";</div><div><br></div><div>if ($statement = /quick/) {</div><div> print "this is what's up\n";</div><div>}</div><div><br></div><div>Now let's look at NSRegularExpression...</div><div><br></div><div>Swift:</div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div>do {</div></blockquote><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div> let pattern = "\\w" // escape everything</div><div> let regex = NSRegularExpression(pattern, options)</div><div> let results = regex.matches(in: str, options: .reportCompletion, range: NSRange(location: 0, length: str.characters.distance(from: str.startIndex, to: str.endIndex)))</div><div><br></div><div> results.forEach {</div><div> print($0) // why is this a NSTextCheckResult?!</div><div> }</div></blockquote><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div>} catch {</div><div> // welp out of luck</div><div>}</div></blockquote><div><br></div><div>Yes I'm fully aware of the method:</div><div><br></div><div> str.replaceOccurences(of: "pattern" with: "something" options: .regularExpression, range: nil) </div><div><br></div><div>but it is just not enough for what is needed. Also, it is confusing to have a replace regex method separate from NSRegularExpression. It was not easy to find. </div><div><br></div><div>Taken from <a href="http://nshipster.com/nsregularexpression/">NSHipster</a>:</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Happily, on one thing we can all agree. In NSRegularExpression, Cocoa has the most long-winded and byzantine regular expression interface you’re ever likely to come across.</blockquote><div><br></div><div>There is no way to achieve the goal of being better at string processing than Perl without regular expressions being addressed. It just should not be ignored. </div></div></div></blockquote><div><br></div>It's not being ignored. We are laying the crucial foundation required for both Regexp support <u>and</u> more general pattern-matching. We do, however, have to do some things later, and a full treatment of regexps is one such thing.</div></div><div><br></div><div>-Dave</div></body></html>