<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 &lt;<a href="mailto:alvaradojoshua0@gmail.com">alvaradojoshua0@gmail.com</a>&gt; 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.&nbsp;</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."&nbsp;</span></blockquote></div></blockquote><div><br></div>We shouldn't have said "this proposal," because it's a manifesto, not a proposal. &nbsp;Addressing Regexps in Swift proper <u>is</u>&nbsp;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&nbsp;have native easy to use regular expression functionality&nbsp;built in.&nbsp;<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>&nbsp; &nbsp;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>&nbsp; &nbsp; let pattern = "\\w" // escape everything</div><div>&nbsp; &nbsp; let regex = NSRegularExpression(pattern, options)</div><div>&nbsp; &nbsp; 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>&nbsp; &nbsp;results.forEach {</div><div>&nbsp; &nbsp; &nbsp; print($0) // why is this a NSTextCheckResult?!</div><div>&nbsp; &nbsp; }</div></blockquote><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div>} catch {</div><div>&nbsp; &nbsp;// 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>&nbsp; &nbsp; str.replaceOccurences(of: "pattern" with: "something" options: .regularExpression, range: nil)&nbsp;</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.&nbsp;</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&nbsp;goal of being better at string processing than Perl without regular expressions being addressed. It just should not be ignored.&nbsp;</div></div></div></blockquote><div><br></div>It's not being ignored. &nbsp;We are laying the crucial foundation required for both Regexp support <u>and</u>&nbsp;more general pattern-matching. &nbsp;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>