<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Sven</title>
    <description>The latest articles on DEV Community by Sven (@svedi).</description>
    <link>https://dev.to/svedi</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F17963%2F11b44439-2bba-44c6-b9cf-339f7d54f499.jpeg</url>
      <title>DEV Community: Sven</title>
      <link>https://dev.to/svedi</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/svedi"/>
    <language>en</language>
    <item>
      <title>TIL: Match unicode letters in regex</title>
      <dc:creator>Sven</dc:creator>
      <pubDate>Wed, 20 Dec 2017 12:41:51 +0000</pubDate>
      <link>https://dev.to/svedi/til-match-unicode-letters-in-regex-55ab</link>
      <guid>https://dev.to/svedi/til-match-unicode-letters-in-regex-55ab</guid>
      <description>&lt;p&gt;Note: This post was originally posted on &lt;a href="https://sven-dittmer.netlify.com/2017/12/20/match-unicode-letters-in-regex.html"&gt;sven-dittmer.netlify.com&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Today I faced an interesting challenge on &lt;a href="http://exercism.io"&gt;exercism.io&lt;/a&gt;.&lt;br&gt;
To me, the most interesting part was about finding out if a sentence was&lt;br&gt;
yelled or not. A sentence counts as yelled if all its word are upper case.&lt;/p&gt;

&lt;p&gt;You can find the whole challenge here: &lt;a href="http://exercism.io/exercises/elixir/bob/readme"&gt;Bob in elixir - exercism.io&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here's my first attempt:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight elixir"&gt;&lt;code&gt;&lt;span class="no"&gt;String&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;upcase&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;input&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;input&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This one passes some tests, but it failes for sentences that don't contain any word, like "&lt;em&gt;1, 2, 3&lt;/em&gt;". Since there's no upper case word, it shouldn't count as yelled.&lt;br&gt;
Next try:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight elixir"&gt;&lt;code&gt;&lt;span class="n"&gt;input&lt;/span&gt; &lt;span class="o"&gt;=~&lt;/span&gt; &lt;span class="sr"&gt;~r/\w/u&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="no"&gt;String&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;upcase&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;input&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;input&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With this regex, I made sure the word contains at least on letter. And since I'm still checking that every letter is upper case, that should do the job, right? Well, not quite.&lt;/p&gt;

&lt;p&gt;The exercise's last test was about a sentence yelled in Russian. (Link:&lt;br&gt;
&lt;a href="http://exercism.io/exercises/elixir/bob/test-suite#L81"&gt;Bob in elixir test suite&lt;/a&gt;)&lt;br&gt;
Turns out &lt;code&gt;\w&lt;/code&gt; matches only letters of the latin alphabet. It is equivalent to &lt;code&gt;[a-zA-Z]&lt;/code&gt;. To make the regex work, I'd have to match any unicode letter. After googling a little bit, I found the solutions here: &lt;a href="https://www.regular-expressions.info/unicode.html"&gt;Regular-Expressions.info&lt;/a&gt;. With PCRE we can match different categories of unicode with &lt;code&gt;\p{&amp;lt;some_unicode_category&amp;gt;}&lt;/code&gt;. For letters, you can use &lt;code&gt;\p{Letter}&lt;/code&gt; or its short form &lt;code&gt;\p{L}&lt;/code&gt;. Here's the final code that makes the last test pass:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight elixir"&gt;&lt;code&gt;&lt;span class="n"&gt;input&lt;/span&gt; &lt;span class="o"&gt;=~&lt;/span&gt; &lt;span class="sr"&gt;~r/[\p{L}]/u&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="no"&gt;String&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;upcase&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;input&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;input&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is my first post on dev.to. Feedback is much appreciated!&lt;/p&gt;

</description>
      <category>todayilearned</category>
      <category>regex</category>
      <category>unicode</category>
    </item>
    <item>
      <title>Hi, I'm Sven</title>
      <dc:creator>Sven</dc:creator>
      <pubDate>Tue, 02 May 2017 21:06:46 +0000</pubDate>
      <link>https://dev.to/svedi/hi-im-sven</link>
      <guid>https://dev.to/svedi/hi-im-sven</guid>
      <description>&lt;p&gt;I have been coding for 10 years (3 years professionally).&lt;/p&gt;

&lt;p&gt;You can find me on GitHub as &lt;a href="https://github.com/svendittmer" rel="noopener noreferrer"&gt;svendittmer&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I live in Hamburg, Germany.&lt;/p&gt;

&lt;p&gt;I work for Brandnooz&lt;/p&gt;

&lt;p&gt;I mostly program in these languages: Ruby.&lt;/p&gt;

&lt;p&gt;I am currently learning more about Linux.&lt;/p&gt;

&lt;p&gt;Nice to meet you.&lt;/p&gt;

</description>
      <category>introduction</category>
    </item>
  </channel>
</rss>
