<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Devon Darrow on Medium]]></title>
        <description><![CDATA[Stories by Devon Darrow on Medium]]></description>
        <link>https://medium.com/@ddarrowphl?source=rss-5258913792fe------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*7rVaoivm0XJGuZUr</url>
            <title>Stories by Devon Darrow on Medium</title>
            <link>https://medium.com/@ddarrowphl?source=rss-5258913792fe------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 16:33:23 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ddarrowphl/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Grommet]]></title>
            <link>https://medium.com/@ddarrowphl/grommet-5a6c5accd45e?source=rss-5258913792fe------2</link>
            <guid isPermaLink="false">https://medium.com/p/5a6c5accd45e</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[components]]></category>
            <category><![CDATA[styled-components]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Devon Darrow]]></dc:creator>
            <pubDate>Tue, 04 Dec 2018 16:43:41 GMT</pubDate>
            <atom:updated>2018-12-04T16:43:41.393Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>An introduction to building a React app with Grommet</strong></p><p>I jump at every chance to incorporate styling into a project. Now that the time has come to build a full-scale React application as a junior developer, that excitement for styling is still very much alive and well. While in the process of discovering React UI libraries to incorporate into my team’s app, I came across a pretty recently created UI library known as <a href="https://v2.grommet.io/">Grommet</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/552/1*mm5cDQAWDh7J_ef_NnxoyA.png" /><figcaption>This little resident Grommet icon-meets-monster/vampire/mouse is my favorite part …</figcaption></figure><p>Grommet, citing itself as a “<a href="https://reactjs.org/">react</a>-based framework that provides accessibility, modularity, responsiveness, and theming in a tidy package,” has very sleek, modern-looking components that anyone can incorporate into an existing React project.</p><p>If you would like to get your feet wet before taking the full plunge, Grommet also has a <a href="https://github.com/grommet/grommet-starter-new-app">starter application</a> that you can load into your browser and play around with to understand the functionality of a few components including a <a href="https://v2.grommet.io/box">Grommet Box</a> and a <a href="https://v2.grommet.io/button">Grommet Button</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/237/1*1CfC8Y_4IkZGP2IBCUhF-w.png" /><figcaption>A Grommet Box</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/158/1*yIvJ_s_EqkqD6yVWOaHvaQ.png" /><figcaption>A Grommet Button</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nKu9xtHLqDJhr9axR-2hkg.png" /><figcaption><a href="https://v2.grommet.io/">https://v2.grommet.io</a> — examples of a few Grommet components</figcaption></figure><p>In terms of installing and using Grommet, the process is fairly straightforward:</p><ol><li>Once inside of your React app in your terminal, run the below command to install Grommet’s packages:</li></ol><pre>npm install grommet grommet-icons styled-components --save</pre><p>2. Next, choose the .js file(s) that you want to import Grommet into:</p><pre>import React, { Component } from &#39;react&#39;;<br>+ import { Grommet } from &#39;grommet&#39;;</pre><p><em>To note</em>: While experimenting with Grommet, I noticed that Grommet needs to be imported at the top of each file you intend to use it with. When I attempted to import it to my parent component (i.e. App.js), Grommet was not then available to all of the App file’s children. This may or may not seem obvious / this could change over time.</p><p>3. Grommet should also be included in a top-level node in whichever component you utilize it in, in order to be able to have it function properly. Here’s some sample code from Grommet’s starter app page to demonstrate:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/524/1*ydTrSXdAnOQYofMvgQitwA.png" /></figure><p>4. You can set up your styling to accompany the Grommet tags with a declaration such as the below, above your function that renders the JSX elements (in the components where you’ve imported Grommet), if you don’t want to/do not yet know how to set up a css loader to parse your css files. In that case, you would put the styling below into that separate file.</p><p>This theme will propagate to all components under this given Grommet instance. However, Grommet notes that if you are working with another library such as Material UI, that is already setting styles in tags with its own typography, Grommet will not be able to affect those styles. However, what is nice about this note is the point that Grommet CAN work with other libraries. I have yet to explore the extent of this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/288/1*0yAYlI8E9k4b1V3TxbMHeA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/291/1*NthzC22sD9Id19xh62af_g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/887/1*OJ51_f58puQB-IMfMpzX8Q.png" /></figure><p>5. For ANY of the Grommet components that you wish to use, you’ll need to import them at the top of your chosen .js file as in the below:</p><pre>- import { Grommet } from &#39;grommet&#39;;<br>+ import { Box, Grommet } from &#39;grommet&#39;;</pre><p>Lastly, there are some further tools that can help you when you’re experimenting with various components:</p><p>a) <a href="https://storybook.grommet.io/?selectedKind=Components&amp;selectedStory=All&amp;full=0&amp;addons=1&amp;stories=1&amp;panelRight=0&amp;addonPanel=storybook%2Fstories%2Fstories-panel"><strong>Storybook</strong></a>: This essentially illustrates how all of the Grommet components work, and while not real application scenarios, will help you get a feel for how the components work</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V6PHkzHOz1L9xLLonkhjEQ.png" /></figure><p>b) <a href="https://codesandbox.io/s/github/grommet/grommet-sandbox"><strong>Grommet Sandbox</strong></a><strong>:</strong> The Sandbox Editor allows you to play with the components and their functionality, although again, these do not have real app scenarios. This way, once you have a component working way you envision in Sandbox, I find it easier to then implement it into my app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3LU1NgGKM5jQoGtwxrn_Ww.png" /></figure><p>c) <strong>Grommet slack: </strong>Grommet happily <a href="https://slackin.grommet.io/">invites</a> all users to join its slack so that you can post any questions you may have about using Grommet.</p><p>While this is only an introduction to Grommet (I’m learning right along with you!), I’m excited to see the evolution of Grommet and to use it again for future applications.</p><p>Happy styling!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5a6c5accd45e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[PSEUDO-CLASSES VS PSEUDO-SELECTORS]]></title>
            <link>https://medium.com/@ddarrowphl/pseudo-classes-vs-pseudo-selectors-58e06f1edc04?source=rss-5258913792fe------2</link>
            <guid isPermaLink="false">https://medium.com/p/58e06f1edc04</guid>
            <category><![CDATA[html]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[website]]></category>
            <dc:creator><![CDATA[Devon Darrow]]></dc:creator>
            <pubDate>Wed, 07 Nov 2018 15:14:47 GMT</pubDate>
            <atom:updated>2018-11-07T15:14:47.661Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>What is the difference between them and why do none of us know? (But really…do you?)</blockquote><p>I n my ongoing attempt to understand the vast world of HTML and CSS, there are always those aspects that fall into a kind of gray area in a developer’s knowledge-base, especially concerning HTML and CSS. I get an ugly-step sister kind of vibe when I observe many (though not all!) developers discuss and tackle these during projects that require them. Two such topics of HTML and CSS that fall into this gray area of knowledge are the existence of the pseudo-class and the pseudo-element, and how both work with HTML and CSS. Here goes my attempt to break them down.</p><p>Generally speaking, a pseudo-class is sort of a phantom state or a specific characteristic of an element that we can target with CSS. Pseudo-classes are preceded by a `<strong>:</strong>`, usually come into play when a user performs an action on the page, and are created with CSS.</p><p>Pseudo-selectors (or elements) on the other hand, are key words, like virtual elements that are treated more similarly to regular HTML elements. These don’t exist on the document tree or DOM either, and can also be created with CSS selectors to style a specific part of a selected element.</p><p>Let’s go through a few examples of classes and then selectors.</p><p><strong>Pseudo-Classes:</strong></p><ol><li><strong>nth-of-type</strong>: selects one or more elements, within a parent’s list of children, based on their source order, often according to a given formula</li></ol><p>To break down the formula the class uses, <a href="http://css-tricks.com/">CSS-Tricks</a>, one of my favorite CSS/HTML go-to resources, explains the following:</p><p>Formula: an+b, where:</p><ul><li>“a” is an integer value</li><li>“n” is the literal letter “n” — this represents a set of increasing positive integers (similar to iterating through an array in JavaScript) as you move through related elements</li><li>“+” is an operator and may be either “+” or “-”</li><li>“b” is an integer and is required if an <strong>operator</strong> is included in the formula</li><li>(By the way, the ‘&lt;pre&gt;&lt;/pre&gt;’ tag is really great for rendering inner text AS IS as it displays text to the page exactly what is typed up in the HTML document)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fNfy0I7XuUKmrQ-0v8oRAQ.png" /></figure><p>2. <strong>nth-last-child</strong>: matches elements within a group of those elements’ siblings, counting from the end element of that specific group</p><ul><li>This class also can utilize a formula to traverse elements</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*elfzvogc7fBDoRNJl4-dng.png" /></figure><p>**To test out the formula mentioned above further, there is a great resource called <a href="https://css-tricks.com/examples/nth-child-tester/#">CSS-Tricks Tester</a> that allows you to play around with selecting various elements on the page according to specified parameters as in the below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sjwtlJEI-lih7UR8Jb63AA.png" /></figure><p>3. <strong>first-of-type / last-of-type</strong>: the first or last element of its type among a group of sibling elements</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c3U6xtxEvUu6pREWZ2oYYg.png" /><figcaption>FIRST-OF-TYPE</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SSrONOH8WCTiq7QA_gqR_w.png" /><figcaption>LAST-OF-TYPE</figcaption></figure><p>4. <strong>Link-related pseudo-classes: </strong>a group of pseudo-classes that are related directly to a user’s interaction with elements on the page such as the <strong>&lt;button&gt; </strong>or<strong> &lt;a&gt; </strong>elements</p><p><strong>:visited</strong> — a link that a user has already visited</p><p><strong>:link </strong>— the actual link within the html tag (usually denoted with the &lt;a&gt;&lt;/a&gt; tag)</p><p><strong>:hover</strong> — the action of a user interacting with an element via a “pointing device” (i.e. mouse)</p><ul><li>It’s worth it to mention that classes like those above need to be written in your CSS in a<strong> specific order. </strong>Any of them can be overridden by a subsequent ‘link’-related pseudo-class if the class doing the overriding has at least equal specificity as the class it overrides. Stick to this order :link — :visited — :hover — :active</li><li>**The :activeclass, by the way, represents an element (such as a button or link) that is being activated by the user</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WecdR_9dTqvfwfoCmBi30Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sejGw7Lji9szt-scwhww-w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yjgd6CToWHrXYCdkAZSklQ.png" /></figure><p><strong>Pseudo-Selectors:</strong></p><p>Let’s move on to pseudo-selectors. As mentioned, these are created with CSS and not within the actual DOM or document tree and are treated as virtual HTML elements though not written into the actual HTML. Let’s look at a few examples below:</p><ol><li><strong>::before / ::after:</strong> allows us to insert “virtual” elements before or after an element’s content that the user can see and are able to be styled in the CSS</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*luoWflKtVId91A34qa9mBQ.png" /></figure><p>* (Note that the double colon was introduced with CSS3 to differentiate between pseudo class syntax (:) and pseudo element syntax (::) although the single colon can be applied to pseudo elements as well)</p><p>2. <strong>::first-letter</strong>: styles only the first letter of the first line of a block-level element.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-4OBQ9zNkr9o36Wa0hty6g.png" /></figure><p>As you can see, pseudo-classes and pseudo-elements are can be difficult to understand and use let alone discern the difference between the two and their uses. With practice though and gaining more knowledge gradually, I am confident that we can all utilize them when we need them. Maybe one day these can go from ugly step-sister status to Cinderella. Maybe…just maybe??</p><p><strong>Sources</strong>:</p><ul><li><a href="https://www.smashingmagazine.com/2016/05/an-ultimate-guide-to-css-pseudo-classes-and-pseudo-elements/#selection">An Ultimate Guide To CSS Pseudo Classes And Pseudo Elements</a></li><li><a href="https://css-tricks.com/almanac/selectors/n/nth-of-type/">:nth-of-type | CSS-Tricks</a></li><li><a href="https://developer.mozilla.org/en-US/docs/Web/CSS/Pseudo-elements#Index_of_standard_pseudo-elements">Pseudo-elements</a></li><li><a href="https://developer.mozilla.org/en-US/docs/Web/CSS/Pseudo-classes#Index_of_standard_pseudo-classes">Pseudo-classes</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=58e06f1edc04" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[“Animating” Rails with CSS]]></title>
            <link>https://medium.com/@ddarrowphl/animating-rails-with-css-284e31c9ce5d?source=rss-5258913792fe------2</link>
            <guid isPermaLink="false">https://medium.com/p/284e31c9ce5d</guid>
            <category><![CDATA[rails]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[animation]]></category>
            <category><![CDATA[gem]]></category>
            <dc:creator><![CDATA[Devon Darrow]]></dc:creator>
            <pubDate>Wed, 24 Oct 2018 17:19:32 GMT</pubDate>
            <atom:updated>2018-10-24T17:19:32.293Z</atom:updated>
            <content:encoded><![CDATA[<p>I am one of “those” budding developers who loves CSS and its awesome powers. When I started my journey with CSS and HTML this summer, I developed a curiosity for the “hot” trends evolving in the world of CSS and discovered that animations are trending like nobody’s business.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FxZqycRHIQkKNa%2Ftwitter%2Fiframe&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FxZqycRHIQkKNa%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FxZqycRHIQkKNa%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="326" frameborder="0" scrolling="no"><a href="https://medium.com/media/74bcea35851f7dec8b65bf46ff7858b9/href">https://medium.com/media/74bcea35851f7dec8b65bf46ff7858b9/href</a></iframe><p>Animations allow developers to do some pretty amazing things both with text and images. <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Animations/Using_CSS_animations">Mozilla</a> has a good overview to reference to get a good feel for them.</p><p>As I’m neck deep in building a new rails application this week, I was yearning for a gem that might satisfy my love for CSS animations. Digging around, I didn’t immediately find a gem per se but I did come across a library that endeared itself to me immediately. Enter <a href="https://daneden.github.io/animate.css/">Animate.css</a>, a cross-browser library chock full of diverse CSS animations.</p><p>For starters, using the library is pretty straight forward as it requires you to simply add the class ‘animated’ to any opening HTML tag where you want to utilize an animation, followed by one of the class names from its library as below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/694/1*GX_VBeZ0UrFvX72fKyOLag.png" /><figcaption><a href="https://github.com/daneden/animate.css">github.com/daneden/animate.css</a></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/411/1*5LwDKJuZ6CM7BmEo35sBnw.png" /></figure><p>You are also able to add custom styling to your CSS selectors, as you would to any class, through animation properties including: animation-duration, animation-delay, and animation-iteration-count:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/345/1*EuKgalIOxmwbN0dwuWmU2g.png" /></figure><p>As a brief refresher or for those that aren’t familiar:</p><p><strong>a) Animation-duration is how long an animation will run on a given page</strong></p><p><strong>b) Animation-delay refers to the length of time that passes before an animation begins to play</strong></p><p><strong>c) Animation-iteration-count sets the number of times an animation can be played before stopping</strong></p><p>Should you so choose, CSS.animate also allows for the ability to add the speed of an animation or the delay of an animation directly onto an element’s class attribute (CSS purists, look the other way…):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/476/1*BUfHAg4bnvXwk1T5T0QzWQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/438/1*SmYdJNTV31uGLoO6uyG79g.png" /><figcaption>github.com/daneden/animate.css</figcaption></figure><p>It is also very possible to do further amazing things in conjunction with jQuery though that is for a later post.</p><p>BUT, how can I use this library with Rails? Thanks to the internet and its’ love for fellow developers, I found several solutions. <a href="http://github.com/TrevorS/animate.css-rails">One</a> that I like involves a few simple terminal commands and file updates in your Rails application:</p><ol><li><strong>Add the below to the Gemfile in your application</strong>:</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/325/1*CradWEc5TkhZ5pDEfBMQqg.png" /></figure><p><strong>2.</strong> <strong>Run </strong><strong>$ bundle in your terminal</strong></p><p><strong>3.</strong> <strong>Add the below to the general application.css file in order to have an application-wide style scope with the library</strong>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/168/1*_vSHR7dtx1s6ki39YE6D2A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*J2tXN3RBkv3QicQDhhh08Q.gif" /><figcaption>Thanks to <a href="http://www.gifrocket.com/">gifrocket.com</a> for the sweet video-to-gif converter</figcaption></figure><p>*Note the below as well for whichever CSS you are using for your application:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/502/1*ibau1q18l2PemF3eL0oKbg.png" /></figure><p><strong>4. Fire up that rails server and test out your animations for whichever view you’ve applied them too! (In my case, I’ve applied them to a ‘show’ page)</strong></p><p><strong>Sources:</strong></p><p><a href="https://www.w3schools.com/cssref/css3_pr_animation-iteration-count.asp">www.w3schools.com/cssref/css3_pr_animation-iteration-count.asp</a></p><p><a href="https://www.w3schools.com/cssref/css3_pr_animation-timing-function.asp">www.w3schools.com/cssref/css3_pr_animation-timing-function.asp</a></p><p><a href="https://robots.thoughtbot.com/css-animation-for-beginners">robots.thoughtbot.com/css-animation-for-beginners</a></p><p><a href="https://github.com/daneden/animate.css">github.com/daneden/animate.css</a></p><p><a href="https://github.com/TrevorS/animate.css-rails">github.com/TrevorS/animate.css-rails</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=284e31c9ce5d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Ruby Regular Expressions (Regex): What /\are\s\you\/ anyway?]]></title>
            <link>https://medium.com/@ddarrowphl/ruby-regular-expressions-regex-what-are-s-you-anyway-e3e506c2b36e?source=rss-5258913792fe------2</link>
            <guid isPermaLink="false">https://medium.com/p/e3e506c2b36e</guid>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[regex]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Devon Darrow]]></dc:creator>
            <pubDate>Fri, 12 Oct 2018 15:16:10 GMT</pubDate>
            <atom:updated>2018-10-12T15:16:10.269Z</atom:updated>
            <content:encoded><![CDATA[<p>This fall, as I began my journey into the world of software development, referencing Stack Overflow naturally became a part of my coding routine. While learning Ruby and mining for solutions to problems, I came across multiple examples of what I at first considered odd looking syntax (aka “black magic”). Case-in-point:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/446/1*gSTf8_IJUfdNCt2nRS970Q.png" /><figcaption>“Oh snaaaaapppppp”</figcaption></figure><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2Fvh9isNb4S2Spa%2Ftwitter%2Fiframe&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2Fvh9isNb4S2Spa%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2Fvh9isNb4S2Spa%2F200.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="340" frameborder="0" scrolling="no"><a href="https://medium.com/media/021a0fd3834ec628653f3e621f40a555/href">https://medium.com/media/021a0fd3834ec628653f3e621f40a555/href</a></iframe><p>After seeing this magic multiple times, I decided to embrace confusion and take a deeper look into what these — regular expressions (regex) — actually symbolize. In a nutshell, regular expressions make up “<em>a sequence of characters that define a search pattern</em>…” In other words, these expressions essentially assist in finding patterns within a string in order to extract parts of such a string to process further. Regex is really powerful when it comes to validating or parsing data, especially when it comes to building larger applications that require a lot of user data (i.e. email address verification).</p><p>For a more in-depth explanation and history, see the full wiki article here: <a href="https://en.wikipedia.org/wiki/Regular_expression">https://en.wikipedia.org/wiki/Regular_expression</a></p><p>(Disclaimer: what follows is by no means an exhaustive explanation of all that is regex, but a jumping off point.😅)</p><p>At a more basic level, regular expressions such as the below function to find a match for a word or even a single letter given:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/482/1*A9oIi6J9MLSkXhl5Q5F4Iw.png" /><figcaption>‘like’ exists in the string, therefore “Match found!” is printed to the terminal</figcaption></figure><p>When creating more complicated expressions, the most common way to define a regular expression is by enclosing it in slashes: // — Inside of these slashes is where the expression itself is found.</p><p>Before we get into some slightly more complicated examples, here’s a quick summary of the most common components of the regex language to get our toes wet:</p><ul><li><strong>String literals</strong>: find a particular piece of text (see example above)</li><li><strong>Anchors</strong>: the beginning and the end of the string, or a word (i.e. ‘<strong>^</strong>’ , ‘<strong>$</strong>’ — beginning and end of a line vs. ‘<strong>\A</strong>’ , ‘<strong>\z</strong>’ to denote the beginning and end of a string)</li><li><strong>Character classes</strong>: define a set of allowed characters — i.e <strong>[a,e,i,o,u]</strong> or <strong>[0-9]</strong></li><li><strong>Quantifiers</strong>: define how often a character is expected to occur in the expression for a match to be found (i.e. ‘<strong>+</strong>’ = at least one or many or ‘<strong>?</strong>’ = none or exactly one)</li><li><strong>Captures</strong>: once a certain part of an expression is marked (<strong>[a-z])</strong>— enclosed in parenthesis), one is able to “capture” this particular part of the expression, so it can be used later on as in for example, in an array</li></ul><p>It’s good to have a general idea of the <strong>characters/symbols</strong> that can formulate an expression as your basis:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1017/1*NUTgcihmCty--ACqlxiCBw.png" /><figcaption>(<a href="http://rubular.com/">http://rubular.com/</a> — life saver right here )</figcaption></figure><p>Regex often includes ranges as in the below, so it’s also helpful to have an idea of what they represent:</p><ul><li><strong>[0–9]</strong> matches any number from 0 to 9</li><li><strong>[a-z]</strong> matches any letter from a to z (no caps)</li><li><strong>[^a-z]</strong> negated range — <strong>Matching anything NOT in the character class (i.e. allows every character that is not whatever follows the ^ )</strong></li><li><strong>\w</strong> = <strong>[0–9,a-z,A-Z_]</strong></li><li><strong>\d</strong> = <strong>[0–9]</strong></li><li><strong>\s</strong> matches <strong>white space</strong> (tabs, regular space, newline)</li></ul><p>And opposite of <strong>\w</strong> ,<strong> \d </strong>&amp; <strong>\s</strong>:</p><ul><li><strong>\W</strong> anything that’s not in <strong>[0–9,a-z,A-Z_]</strong></li><li><strong>\D</strong> anything that’s not a number</li><li><strong>\S</strong> anything that’s not a space</li><li>The dot character . matches any single character. If you need to use a literal . in your expression then you have to \<strong>escape it</strong>\ as in the below:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/236/1*wlAyUqibdm8hSuZ9QHR9vQ.png" /></figure><p>Let’s break down a few more examples. Ready? Alright me too.</p><p>A) To start, how about creating strings with a specific amount of characters?</p><p>The below could be read as ‘<strong>\A</strong>’ begins the string and counts as the first character, ‘<strong>\w</strong>’ signifies any character, ‘<strong>{6}’ </strong>denotes the exact amount of characters the string can have (in our case 6 including the ‘<strong>\A’ </strong>and ‘<strong>\z’</strong>), and ‘<strong>\z</strong>’ denotes the end of the string/last character of the string:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/995/1*ASBKqv3B6Ac3GVyniWGE8A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/995/1*5PZphrlJRDDGLfiLQej1wg.png" /><figcaption>Courtesy of: <a href="http://rubular.com/">rubular.com</a></figcaption></figure><p>The above expression is similar to the expression with ‘<strong>{6}’</strong> characters only here we denote ‘<strong>{4}’</strong> maximum while the ‘<strong>^</strong>’ begins the line (not string in this case) and the ‘<strong>$</strong>’ ends the line (not string in this case)</p><p>B) Let’s say we have an IP address: “<strong>192.168.1.1</strong>” — How can I write this out at a general level with regex? Very, very slowly:</p><p><strong>/^\d{1,3}\. \d{1,3}\. \d{1,3}\.\d{1,3}$/</strong></p><ol><li><strong>^\d{1,3}\.</strong></li></ol><p>The <strong>^</strong> begins the line in this case, <strong>\d</strong> is any digit where <strong>{1,3}</strong> is any three characters from 0–999 so ‘<strong>192</strong>’ fits that, and <strong>\. </strong>represents an actual ‘<strong>.</strong>’</p><p>2. \<strong>d{1,3}\.</strong></p><p>Same as the above for ‘<strong>168</strong>’ without the beginning ‘<strong>^</strong>’</p><p>3. \<strong>d{1,3}\.</strong></p><p>Here <strong>\d</strong> is any digit where <strong>{1,3} </strong>signifies any three characters from 0–999 so ‘<strong>1</strong>’ fits that and…</p><p>4. \<strong>d{1,3}$</strong></p><p><strong>\d</strong> is any digit where <strong>{1,3} </strong>signifies any three characters from 0–999 so ‘<strong>1</strong>’ fits that as well</p><p><strong>*It’s important to note that the above regex fits not only the specified IP address but a slew of other variations as well (naturally…). You could drill down farther to get more a more specific pattern for your specific IP address (and you probably should because 999.999.999.999 is not a valid IP address).</strong></p><p>C) How about to check if simple string is made of whole numbers?</p><p>“123”.match?(<strong>/\A-?\d+\Z/</strong>)</p><p>Starting with the <strong>\A , </strong>check for an optional dash (<strong>-?</strong>, for negative numbers), then make sure there are some numbers following the digit denoted by ‘<strong>\d</strong>’ (<strong>\d+</strong>) and nothing else until the end of the string <strong>\Z</strong></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FoLkalyqBkSIg0%2Ftwitter%2Fiframe&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FoLkalyqBkSIg0%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FoLkalyqBkSIg0%2Fgiphy-downsized-large.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="237" frameborder="0" scrolling="no"><a href="https://medium.com/media/6610a067eb8999c7feb4c794270296a9/href">https://medium.com/media/6610a067eb8999c7feb4c794270296a9/href</a></iframe><p>As you can see, it feels a little like the wild west out there when creating regular expressions. My advice is to start playing around with more simple expressions. I’ll be right there with you testing… and testing… and testing :</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2Fl4hLCHEdxOGxMcWFG%2Ftwitter%2Fiframe&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2Fl4hLCHEdxOGxMcWFG%2Fgiphy.gif&amp;image=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2Fl4hLCHEdxOGxMcWFG%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="252" frameborder="0" scrolling="no"><a href="https://medium.com/media/31054be684c4fe8191c7eaaa1c355f36/href">https://medium.com/media/31054be684c4fe8191c7eaaa1c355f36/href</a></iframe><p>Look to these sites as well for a good starting place to test out your expressions:</p><ul><li><a href="http://rubular.com/">Rubular: a Ruby regular expression editor and tester</a></li><li><a href="https://regexr.com/">RegExr: Learn, Build, &amp; Test RegEx</a></li></ul><p>Happy testing</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e3e506c2b36e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>