<?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: kbrock84</title>
    <description>The latest articles on DEV Community by kbrock84 (@kbrock84).</description>
    <link>https://dev.to/kbrock84</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%2F66685%2F979183be-de07-4573-aba9-57f300cfe3c7.jpeg</url>
      <title>DEV Community: kbrock84</title>
      <link>https://dev.to/kbrock84</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/kbrock84"/>
    <language>en</language>
    <item>
      <title>GitHub Driven Debugging</title>
      <dc:creator>kbrock84</dc:creator>
      <pubDate>Fri, 14 Jun 2019 12:45:18 +0000</pubDate>
      <link>https://dev.to/kbrock84/github-driven-debugging-3502</link>
      <guid>https://dev.to/kbrock84/github-driven-debugging-3502</guid>
      <description>&lt;h1&gt;
  
  
  GitHub Driven Debugging
&lt;/h1&gt;

&lt;p&gt;These days, there are many tools at your disposal for debugging, no matter what your stack is. But after hours of no results, sometimes you need to look beyond your code to understand... your code.&lt;/p&gt;

&lt;p&gt;GitHub is huge, and almost all of the open source projects I use are hosted on it. This is &lt;em&gt;my&lt;/em&gt; process for debugging issues via GitHub.&lt;/p&gt;

&lt;h2&gt;
  
  
  Check the README.MD and Docs
&lt;/h2&gt;

&lt;p&gt;The first step I always take is reading through the project's &lt;code&gt;README.MD&lt;/code&gt; file. Check for known issues or a debugging guide and be sure you are using the project as intended.&lt;/p&gt;

&lt;p&gt;If I don't have any luck in the readme I read through the docs, if any. Typically I start by searching for the specific part of the library that I am using, and then expand my search to see if there is a better way to accomplish what I am trying.&lt;/p&gt;

&lt;h2&gt;
  
  
  Digging into the Issues
&lt;/h2&gt;

&lt;p&gt;I often search GitHub issues, while debugging errors from external libraries, to see if other people have similar problems. Many times this is the easiest way to find a fix.&lt;/p&gt;

&lt;p&gt;If there are many people with the same issue, you may need to dig deep through one or more issues to find a resolution. The solution can be buried deep in all the comments. Be sure to check open issues, then closed issues. I find most fixes in a closed issue, but if it's a problem with the library you're on a wild goose chase in the closed issues. My favorite way to keep track of these issue comments is with bookmarks in my browser:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Click the 3 dots on the top right of the comment.&lt;/li&gt;
&lt;li&gt;Click &lt;code&gt;Copy Link&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Paste it in as the URL and navigate to the new link. You should see that the comment is now highlighted.&lt;/li&gt;
&lt;li&gt;Bookmark the page before doing anything else. If you click out of the comment you will loose the comment address and the bookmark will be for the issue itself.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Digging into the Source Code
&lt;/h2&gt;

&lt;p&gt;If I don't find a fix in the issues (or if I'm just curious) I dig into the source code of the project - especially the parts I'm using and how the project initializes. Having an awareness of the inner workings of your tools can come in very handy. I can't tell you how many times I've spent hours debugging an issue, only to spend 15 minutes looking at the source code and having that &lt;strong&gt;"OH THAT'S WHY!"&lt;/strong&gt; moment.&lt;/p&gt;

&lt;p&gt;Some projects are very large and complex, so digging into the source may sound (and be) overwhelming, but I believe it's especially worth it for projects you commonly use.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Last Resort (Creating an Issue)
&lt;/h2&gt;

&lt;h3&gt;
  
  
  But why is this the last resort?
&lt;/h3&gt;

&lt;p&gt;To rephrase the question: why should you exhaust all other options before creating an issue on GitHub?&lt;/p&gt;

&lt;p&gt;Most GitHub project maintainers are working on open source in their spare time and that time is precious. You want to be sure that your issue is not a duplicate and that you clearly understand the problem you are having (at least as much as you possibly can).&lt;/p&gt;

&lt;p&gt;One of the greatest advantages you have from the time spent reading the docs, issues and source code, is deeper knowledge of the project. This will not only help you describe your issue, but also understand feedback from the maintainers. If you've taken the time to read through the source code and feel the issue has something to do with the project, you can submit a pull request to fix it. Just be sure you have reviewed the projects &lt;code&gt;CONTRIBUTING.MD&lt;/code&gt; if there is one.&lt;/p&gt;

&lt;h3&gt;
  
  
  So what makes a good issue?
&lt;/h3&gt;

&lt;p&gt;First: &lt;strong&gt;Be kind and respectful&lt;/strong&gt;. The project you are using is being provided for &lt;strong&gt;free&lt;/strong&gt;. It's okay to be frustrated, but don't vent your frustration to the maintainers. They have enough to deal with.&lt;/p&gt;

&lt;p&gt;Second: It's okay if the initial issue has a lot of information.&lt;/p&gt;

&lt;p&gt;You should be able to reproduce your issue in a small project with minimal code to get it running (and breaking). Provide this code, or a link to it. Also include the exact error message you get from the code. The maintainers may not be able to reproduce the error with the code you provide.&lt;/p&gt;

&lt;p&gt;Include the exact steps taken to reproduce the error as numbered items. Test these steps yourself before submitting to ensure you don't miss anything.&lt;/p&gt;

&lt;p&gt;Provide any and all relevant information about your setup. Include things like the operating system you are using, browsers tested in, other libraries/frameworks used etc. Dig deep into what may be affecting your program. &lt;/p&gt;

&lt;p&gt;Format for readability. Use white space and headings to group your issue into logical blocks. Include screenshots and code snippets as necessary. GitHub uses Markdown. Read through the &lt;a href="https://guides.github.com/features/mastering-markdown/"&gt;Mastering Markdown&lt;/a&gt; guide if you are not familiar.&lt;/p&gt;

&lt;p&gt;You made it to the end! That's all for now. Thanks for reading!&lt;/p&gt;

</description>
      <category>github</category>
      <category>debugging</category>
      <category>opensource</category>
      <category>beginners</category>
    </item>
    <item>
      <title>RegEx Necessities Part 1</title>
      <dc:creator>kbrock84</dc:creator>
      <pubDate>Sun, 12 May 2019 14:22:46 +0000</pubDate>
      <link>https://dev.to/kbrock84/regex-necessities-part-1-4olh</link>
      <guid>https://dev.to/kbrock84/regex-necessities-part-1-4olh</guid>
      <description>&lt;h2&gt;
  
  
  TL;DR
&lt;/h2&gt;

&lt;p&gt;Regular expressions are easier than you think. Let's focus on the bare necessities in a quick and dirty reference with examples in JavaScript. If you are new to regular expressions or need a quick review on the basics, this is a great place to start. We'll dive deeper into use cases in part 2.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Regex?
&lt;/h2&gt;

&lt;p&gt;Regular expressions is a concise language for matching patterns of text. In JavaScript, a regular expression can be defined like this &lt;code&gt;/expression/&lt;/code&gt;. In it's most basic form a regular expression can look like this:&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nx"&gt;pizza&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;entree&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Hint: If you would like to follow along and play with some of these expressions, I've found &lt;a href="https://www.regexpal.com/"&gt;Regex Pal&lt;/a&gt; to be very helpful&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;In the above example, if the &lt;code&gt;entree&lt;/code&gt; variable contained &lt;code&gt;pizza&lt;/code&gt; anywhere within the string, it will return true. Some examples that will return true: &lt;code&gt;pizza&lt;/code&gt; &lt;code&gt;pizzas&lt;/code&gt; &lt;code&gt;spizzas&lt;/code&gt; &lt;code&gt;i like to eat pizza&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Don't Fear RegEx
&lt;/h2&gt;

&lt;p&gt;Regular expressions can look intimidating if you haven't had some experience with them. If you can write code you can learn regular expressions. It's just syntax and almost every language supports them. I use regular expressions almost daily to search for files. You know, those files someone is looking for, on that server that so many people have touched. This can be maddening without the right tool.&lt;/p&gt;

&lt;p&gt;There are however, some cases where you should just reach for a library. One notorious example is validating email. If a regular expression gets too complex, it can become difficult to debug and maintain. So let someone else do that work if you can.&lt;/p&gt;

&lt;p&gt;Okay lets look at the operators first. Remember, this is not a comprehensive list. Just enough to get started. I'll list resources at the end.&lt;/p&gt;

&lt;h2&gt;
  
  
  Operators
&lt;/h2&gt;

&lt;p&gt;There are a few must know operators. Master these and you will cover the majority of use cases. I'll start with an example, and then explain what's happening.&lt;/p&gt;

&lt;p&gt;It's important to note that the following examples are case sensitive. The expression &lt;code&gt;/B/&lt;/code&gt; is different than the expression &lt;code&gt;/b/&lt;/code&gt;. This can be changed with a &lt;em&gt;modifier&lt;/em&gt; which we'll discuss later.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Wild Card &lt;code&gt;*&lt;/code&gt;:
&lt;/h3&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/cat*/.test("category");
// returns true
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The simplest operator, &lt;code&gt;*&lt;/code&gt; matches any character or combination of characters for any length. Lets see some examples of matches and mismatches.&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;matchRed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sr"&gt;/red*/&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;matchRed&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"reddit"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// returns true&lt;/span&gt;
&lt;span class="nx"&gt;matchRed&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"credit"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// returns true&lt;/span&gt;
&lt;span class="nx"&gt;matchRed&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"brew"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// returns true&lt;/span&gt;
&lt;span class="nx"&gt;matchRed&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"book"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// returns false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;So what's happening here? The wildcard will match any combination of text &lt;strong&gt;after&lt;/strong&gt; the combination &lt;code&gt;re&lt;/code&gt; is found. But wait! We wanted to match &lt;code&gt;red&lt;/code&gt; not &lt;code&gt;re&lt;/code&gt;. How do we remedy this? The &lt;code&gt;*&lt;/code&gt; makes the last character an optional one, so really it matches anything. We can add an extra character to the expression using the &lt;code&gt;.&lt;/code&gt; operator like this:&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nx"&gt;red&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="sr"&gt;/.test&lt;/span&gt;&lt;span class="se"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;"brew"&lt;/span&gt;&lt;span class="se"&gt;)&lt;/span&gt;&lt;span class="sr"&gt;; /&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nx"&gt;returns&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;More on the &lt;code&gt;.&lt;/code&gt; below.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Dot &lt;code&gt;.&lt;/code&gt;
&lt;/h3&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;matchAt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sr"&gt;/.at/&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;matchAt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"cat"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// returns true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;.&lt;/code&gt; operator matches any character one time. In the above example it matches cat. Lets take a look at a some other examples.&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;matchAt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sr"&gt;/.at/&lt;/span&gt;
&lt;span class="nx"&gt;matchAt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"rat"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// returns true&lt;/span&gt;
&lt;span class="nx"&gt;matchAt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"bat"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// returns true&lt;/span&gt;
&lt;span class="nx"&gt;matchAt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"#at"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// returns true&lt;/span&gt;
&lt;span class="nx"&gt;matchAt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"at"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// returns false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Okay. What's going on here. &lt;code&gt;rat&lt;/code&gt;, &lt;code&gt;bat&lt;/code&gt; and &lt;code&gt;#at&lt;/code&gt; match because we specified any single character with the &lt;code&gt;.&lt;/code&gt; and the letters &lt;code&gt;at&lt;/code&gt; after. Just the letters &lt;code&gt;at&lt;/code&gt; fail because there is no character in front of the letters.&lt;/p&gt;

&lt;h3&gt;
  
  
  Word Character &lt;code&gt;\w&lt;/code&gt;
&lt;/h3&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;matchAt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;\w&lt;/span&gt;&lt;span class="sr"&gt;at/&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;matchAt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"cat"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// returns true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Almost&lt;/em&gt; identical to the &lt;code&gt;.&lt;/code&gt; operator, The &lt;code&gt;\w&lt;/code&gt; operator matches any &lt;em&gt;word&lt;/em&gt; character one time. This means it will match any letter or number (and also underscores &lt;code&gt;_&lt;/code&gt;).&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;matchAt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;\w&lt;/span&gt;&lt;span class="sr"&gt;at/&lt;/span&gt;
&lt;span class="nx"&gt;matchAt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"rat"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// returns true&lt;/span&gt;
&lt;span class="nx"&gt;matchAt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"bat"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// returns true&lt;/span&gt;
&lt;span class="nx"&gt;matchAt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"#at"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// returns false&lt;/span&gt;
&lt;span class="nx"&gt;matchAt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"at"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// returns false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  Digits &lt;code&gt;\d&lt;/code&gt;
&lt;/h3&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;matchNumber&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sr"&gt;/number&lt;/span&gt;&lt;span class="se"&gt;\d&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;matchNumber&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"number1"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// returns true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;In the expression above, we will match anything that contains the letters &lt;code&gt;number&lt;/code&gt; followed by any digit hence the &lt;code&gt;\d&lt;/code&gt; operator. Here are a few more examples.&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;matchNumber&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sr"&gt;/number&lt;/span&gt;&lt;span class="se"&gt;\d&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;matchNumber&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"number9"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// returns true&lt;/span&gt;
&lt;span class="nx"&gt;matchNumber&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"somenumber8plus"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// returns true&lt;/span&gt;
&lt;span class="nx"&gt;matchNumber&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"4"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// returns false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;So even if the sequence &lt;code&gt;number8&lt;/code&gt; is in the middle of the string, it will return true.&lt;/p&gt;

&lt;h3&gt;
  
  
  Word Boundary &lt;code&gt;\b&lt;/code&gt;
&lt;/h3&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;matchMoo&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;\b&lt;/span&gt;&lt;span class="sr"&gt;moo&lt;/span&gt;&lt;span class="se"&gt;\b&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;matchMoo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"the cow says moo"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// returns true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;\b&lt;/code&gt; operator matches boundaries of words. The cow can only say moo. That's it. If we were to test a few more cases:&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;matchMoo&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;\b&lt;/span&gt;&lt;span class="sr"&gt;moo&lt;/span&gt;&lt;span class="se"&gt;\b&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;matchMoo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"I have a moo cow"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// returns true&lt;/span&gt;
&lt;span class="nx"&gt;matchMoo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"the cow says moot"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// returns false&lt;/span&gt;
&lt;span class="nx"&gt;matchMoo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"the cow says smoo"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// returns false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Simple enough. If the word &lt;code&gt;moo&lt;/code&gt; and only that word is anywhere in the sentence, it will return true.&lt;/p&gt;

&lt;h3&gt;
  
  
  Character Classes &lt;code&gt;[]&lt;/code&gt;
&lt;/h3&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;matchThese&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;[&lt;/span&gt;&lt;span class="sr"&gt;1Aa&lt;/span&gt;&lt;span class="se"&gt;]&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;matchThese&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"pineapple"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// returns true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Character classes are a powerful part of regex. In the above example, any word containing &lt;code&gt;1&lt;/code&gt;, &lt;code&gt;A&lt;/code&gt; or &lt;code&gt;a&lt;/code&gt; will return true. pretty straight forward right? How about these examples.&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"banana"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// returns true&lt;/span&gt;
&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;[&lt;/span&gt;&lt;span class="sr"&gt;A-E&lt;/span&gt;&lt;span class="se"&gt;]&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"banana"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// returns false&lt;/span&gt;
&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;[&lt;/span&gt;&lt;span class="sr"&gt;1-5&lt;/span&gt;&lt;span class="se"&gt;]&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"The number 3"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// returns true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Inside character classes we can define ranges of numbers, lowercase characters or uppercase characters. You can even combine them.&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;matchThis&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;[&lt;/span&gt;&lt;span class="sr"&gt;a-eA-E1-5&lt;/span&gt;&lt;span class="se"&gt;]&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;matchThis&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"banana"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// returns true&lt;/span&gt;
&lt;span class="nx"&gt;matchThis&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"BANANA"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// returns true&lt;/span&gt;
&lt;span class="nx"&gt;matchThis&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"3"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// returns true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now we have one regular expression to match all words containing letters from a to e and numbers from 1 to 5.&lt;/p&gt;

&lt;h3&gt;
  
  
  Start &lt;code&gt;^&lt;/code&gt;
&lt;/h3&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;/^&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"apple"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;//returns true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;^&lt;/code&gt; represents the beginning of a string. Lets look at a couple of cases where this would return false.&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;/^&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"pineapple"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;//returns false&lt;/span&gt;
&lt;span class="sr"&gt;/^a/&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"eat apples"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;//returns false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;These fail because the string does not start with &lt;code&gt;a&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  End &lt;code&gt;$&lt;/code&gt;
&lt;/h3&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nx"&gt;e$&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"apple"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// returns true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;$&lt;/code&gt; represents the end of a string, so because &lt;code&gt;apple&lt;/code&gt; ends in &lt;code&gt;e&lt;/code&gt;, it returns true. Simple enough, but here are some failing cases to be clear.&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nx"&gt;e$&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"eat"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// returns false&lt;/span&gt;
&lt;span class="sr"&gt;/e$/&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"street"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// returns false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Both cases fail simply because they do not end in &lt;code&gt;e&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Modifiers
&lt;/h2&gt;

&lt;p&gt;Modifiers are less about matching a pattern, but help describe how you would like to search. In JavaScript we have 6 total, but the 3 must know modifiers are &lt;code&gt;i&lt;/code&gt;, &lt;code&gt;m&lt;/code&gt; and &lt;code&gt;g&lt;/code&gt;. These modifiers can be used individually, or in any combination and are placed just after the last &lt;code&gt;/&lt;/code&gt; like this &lt;code&gt;/expression/m&lt;/code&gt; where &lt;code&gt;m&lt;/code&gt; is the modifier.&lt;/p&gt;

&lt;h3&gt;
  
  
  Ignore Case &lt;code&gt;i&lt;/code&gt;
&lt;/h3&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nx"&gt;c&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Coffee"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// returns true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This one is pretty self explanatory. Placing the &lt;code&gt;i&lt;/code&gt; modifier after the expression allows us to match anything containing a lower case &lt;code&gt;c&lt;/code&gt; and an uppercase &lt;code&gt;C&lt;/code&gt;.&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;matchBat&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sr"&gt;/bat/i&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;matchBat&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"WOMBAT"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// returns true&lt;/span&gt;
&lt;span class="nx"&gt;matchBat&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Bat"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// returns true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  Multiline &lt;code&gt;m&lt;/code&gt;
&lt;/h3&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;groceryList&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`apples
oranges
peaches
coffee
chocolate`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="sr"&gt;/coffee/m&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;groceryList&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// returns true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The multiline modifier allows the regular expression to look beyond any new lines. Without it, the above example would return false.&lt;/p&gt;

&lt;h3&gt;
  
  
  Global &lt;code&gt;g&lt;/code&gt;
&lt;/h3&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="s2"&gt;"apple"&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/p/g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"b"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// returns abble&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;A great way to use the JavaScript &lt;code&gt;String.replace&lt;/code&gt; is with regular expressions. However, If you want to replace &lt;strong&gt;all&lt;/strong&gt; occurrences of a matched pattern, you need to include to &lt;code&gt;g&lt;/code&gt; modifier to search globally. Without it, the above expression will only replace the first &lt;code&gt;p&lt;/code&gt; it finds.&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="s2"&gt;"apple"&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/p/&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// returns abple&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h4&gt;
  
  
  That's all for now. Stay tuned for &lt;em&gt;Regex Necessities Part 2&lt;/em&gt;, where we dive deeper into use cases, putting it all together.
&lt;/h4&gt;

&lt;h3&gt;
  
  
  Resources
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp"&gt;RegExp Object MDN&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.w3schools.com/jsref/jsref_obj_regexp.asp"&gt;RegExp Reference w3schools&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.regexpal.com/"&gt;Regex Pal&lt;/a&gt;&lt;/p&gt;

</description>
      <category>regex</category>
      <category>regularexpressions</category>
      <category>javascript</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
