Days 12 & 13: Regular Expressions

Days 12 & 13: Regular Expressions

#100DaysOfCode Challenge

Photo by Joshua Reddekopp on Unsplash

It’s been a busy first week at school, but I’ve still managed to get some coding time in. Here are my log entries for Day 12 (yesterday) and Day 13 (today) for the #100DaysOfCode challenge.

Day 12: August 17, 2022

Today’s Progress:

Today I worked on the Regular Expressions section (93% done so far). The main focuses of the challenges included different combinations of matching (e.g., matching everything, everything but numbers, everything but letters. etc.), positive and negative lookaheads, and checking for mixed groupings. Here are my notes from today’s session:

Quotes & Key Ideas:

  • “You can search for whitespace using \s, which is a lowercase s. This pattern not only matches whitespace, but also carriage return, tab, form feed, and new line characters."
  • “Search for non-whitespace using \S, which is an uppercase s. This pattern will not match whitespace, carriage return, tab, form feed, and new line characters."
  • “Quantity specifiers are used with curly brackets ({ and }). You put two numbers between the curly brackets - for the lower and upper number of patterns. For example, to match only the letter a appearing between 3 and 5 times in the string ah, your regex would be /a{3,5}h/."
  • “You can specify the possible existence of an element with a question mark, ?. This checks for zero or one of the preceding element. You can think of this symbol as saying the previous element is optional."
  • “Lookaheads are patterns that tell JavaScript to look-ahead in your string to check for patterns further along. This can be useful when you want to search for multiple patterns over the same string.” Positive lookaheads look for a match while negative lookaheads look to see if there isn’t a match.
  • “Sometimes we want to check for groups of characters using a Regular Expression and to achieve that we use parentheses (). If you want to find either Penguin or Pumpkin in a string, you can use the following Regular Expression: /P(engu|umpk)in/g

Thoughts:

Yesterday, I was feeling pretty confident with the regexes but today the syntax seemed harder for my brain to process. I think I might need to practice them a bit more. However, I worked on this during the afternoon when I would have preferred to take a nap — it’s the first week of school and I’m feeling the drain on my energy levels. With school starting I think I might need to adjust my goals a bit; instead of aiming for a full hour of code each day I think I might aim for 30 minutes. This will be easier to meet and if I have the energy (or momentum) I can always keep doing.

For my progress visit the timeline on my freeCodeCamp Profile.


Day 13: August 18, 2022

Today’s Progress:

Today I finished the final challenges for the Regular Expressions section on freeCodeCamp AND I was able to complete the 12 challenges for the Debugging. Here are my notes from today’s session:

Quotes & Key Ideas:

  • “You can search and replace text in a string using .replace() on a string. The inputs for .replace() is first the regex pattern you want to search for. The second parameter is the string to replace the match or a function to do something."
  • Firefox and Chrome have DevTools to help with debugging JavaScript
  • The console.log() method can be strategically placed at points within in your code so you know what's happening as the program is being run. This helps with knowing where to look when something goes wrong.
  • typeof can be used to check the data structure/type of a variable
  • “JavaScript recognizes seven primitive (immutable) data types: Boolean, Null, Undefined, Number, String, Symbol (new with ES6), and BigInt (new with ES2020), and one type for mutable items: Object. Note that in JavaScript, arrays are technically a type of object."

Thoughts:

The syntax of the regular expressions can be a little tricky, but I think I’m getting the hang of it. I really enjoyed the debugging challenges. It was really useful to read the code in a program and know that there was an error somewhere. It reinforced some previous concepts of how everything fits together. It also felt a little bit like the coding version of Where’s Waldo?. Overall, I felt great about today’s session and I’m looking forward to learning about Basic Data Structures in JavaScript.

For my progress visit the timeline on my freeCodeCamp Profile.

The full log of my #100DaysOfCode journey can be viewed on GitHub.