<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="">Yeah… that verbal expressions thing looks really cool, but it’s not a substitute for the “real thing”. If we put the testing bit in a protocol, anything that validates text could conform to it and automatically be usable with switches and such:<div class=""><div style="margin: 0px; line-height: normal; font-family: 'Fira Mono'; color: rgb(147, 161, 161);" class=""><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #d33682" class="">protocol</span> RegExValidator {</div><div style="margin: 0px; line-height: normal;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #d33682" class="">func</span> validateRegEx(<span style="font-variant-ligatures: no-common-ligatures; color: #d33682" class="">_</span>: <span style="font-variant-ligatures: no-common-ligatures; color: #278bd2" class="">String</span>) -&gt; <span style="font-variant-ligatures: no-common-ligatures; color: #278bd2" class="">Bool</span></div><div style="margin: 0px; line-height: normal;" class="">}</div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #d33682" class="">func</span> ~= (lhs: <span style="font-variant-ligatures: no-common-ligatures; color: #278bd2" class="">String</span>, rhs: <span style="font-variant-ligatures: no-common-ligatures; color: #29a198" class="">RegExValidator</span>) -&gt; <span style="font-variant-ligatures: no-common-ligatures; color: #278bd2" class="">Bool</span> {</div><div style="margin: 0px; line-height: normal;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #d33682" class="">return</span> rhs.<span style="font-variant-ligatures: no-common-ligatures; color: #29a198" class="">validateRegEx</span>(lhs)</div><div style="margin: 0px; line-height: normal;" class="">}</div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #d33682" class="">func</span> ~= (lhs: <span style="font-variant-ligatures: no-common-ligatures; color: #29a198" class="">RegExValidator</span>, rhs: <span style="font-variant-ligatures: no-common-ligatures; color: #278bd2" class="">String</span>) -&gt; <span style="font-variant-ligatures: no-common-ligatures; color: #278bd2" class="">Bool</span> {</div><div style="margin: 0px; line-height: normal;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #d33682" class="">return</span> lhs.<span style="font-variant-ligatures: no-common-ligatures; color: #29a198" class="">validateRegEx</span>(rhs)</div><div style="margin: 0px; line-height: normal;" class="">}</div><div class=""><br class=""></div></div></div><div class=""><div class="">
- Dave Sweeris

</div>
<br class=""><div><blockquote type="cite" class=""><div class="">On Feb 1, 2016, at 02:02, Haravikk 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=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On 1 Feb 2016, at 03:48, John Randolph 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=""><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">Perl 6’s regex implementation looks like a &nbsp;logical progression of the grep style as we’ve come to know it over the years, but I’d really like to see Swift go with something like the Verbal Expressions approach.</div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class=""></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="https://github.com/VerbalExpressions/SwiftVerbalExpressions" class="">https://github.com/VerbalExpressions/SwiftVerbalExpressions</a></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class=""></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">All the power is there, but it’s far more readable.</div></div></blockquote><br class=""></div><div class="">I like the verbal expressions syntax, could we do both? i.e- instead of mapping straight onto NSRegularExpression, could we have a Swift RegularExpression struct that can either take a traditional regular expression, or be constructed via verbal expressions? It might be mapped onto NSRegularExpression behind the scenes, but could let us use both forms easily.</div></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>