Ending Regular Expressions: Learning JavaScript
Today, I will finish the regular expressions section of the JavaScript BootCamp I have been doing for the past month. This section of the course was pretty tricky. I pulled through in the end though. So here are the last bits of code I learned.

Quantity Specifiers
In this section, I will use the quantity specifiers to specify upper and lower matches in patterns. That involves curly braces. I put two numbers in the curly braces. That is the number of times a character can match during an expression.
let ohStr "Ohhh no";
let ohRegex = /Oh{3,6} no/; // Change this line
let result = ohRegex.test(ohStr);
// Lower Number of Matches
let haStr = "Hazzzzah";
let haRegex = /Haz{4,}ah/; // Change this line
let result = haRegex.test(haStr);
// Exact Number of Matches
let timStr = "Timmmmber";
let timRegex = /Tim{4}ber/; // Change this line
let result = timRegex.test(timStr);
Checking Existence
Using the question mark operator, I can check for elements that may or may not exist in an expression. So in the English language, there are inconsistencies in spelling. Sometimes, the word ‘favorite’ can be spelled with ‘o’, and sometimes it is spelled with ‘ou’. Here is a code example of what I am talking about:
let favWord = "favorite";
let favRegex = /favou?rite/; // Change this line
let result = favRegex.test(favWord);Positive and Negative Lookaheads
I will use lookaheads to check for patterns in a string that come down the line. They said it would be good to check for different patterns over strings. There are two types of lookaheads: positive and negative lookaheads. They are both slightly different so let’s get into it.
// Positive Lookahead
let sampleWord = "astronaut";
let pwRegex = /(?=\w{6})(?=\D*\d{2})/; // Change this line
let result = pwRegex.test(sampleWord);
// Mixed Character Grouping
let myString = "Eleanor Roosevelt";
let myRegex = /(Eleanor|Franklin) (([A-Z]\.?|[A-Z][a-z]+) )?Roosevelt/; // Change this line
let result = myRegex.test(myString); // Change this line
// Capture Groups
let repeatNum = "42 42 42";
let reRegex = /^(\d+) \1 \1$/; // Change this line
let result = reRegex.test(repeatNum);
// Last Problem
let hello = " Hello, World! ";
let wsRegex = /^\s+|\s+$/gi; // Change this line
let result = hello.replace(wsRegex, ""); That was the final problem in the regex. At long last, I can move on from this tiresome section. I hope you all enjoyed the regular expressions part of this vlog. The upcoming section will be about debugging. That should be fun. Keep reading for that.






