Skip to content

Commit 8d6e9c0

Browse files
committed
Regular Expressions (ex. 1 to 33)
+ Finished Regular Expressions module
1 parent 4c4e3b2 commit 8d6e9c0

35 files changed

+586
-34
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/*
2+
Using the Test Method:
3+
Apply the regex myRegex on the string myString using the .test() method.
4+
5+
- You should use .test() to test the regex.
6+
- Your result should return true.
7+
*/
8+
let myString = "Hello, World!";
9+
let myRegex = /Hello/;
10+
let result = myRegex.test(myString); // Changed this line
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/*
2+
Match Literal Strings:
3+
Complete the regex waldoRegex to find "Waldo" in the string waldoIsHiding with a literal match.
4+
5+
- Your regex waldoRegex should find the string Waldo
6+
- Your regex waldoRegex should not search for anything else.
7+
- You should perform a literal string match with your regex.
8+
*/
9+
let waldoIsHiding = "Somewhere Waldo is hiding in this text.";
10+
let waldoRegex = /Waldo/; // Changed this line
11+
let result = waldoRegex.test(waldoIsHiding);
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
Match a Literal String with Different Possibilities:
3+
Complete the regex petRegex to match the pets dog, cat, bird, or fish.
4+
5+
- Your regex petRegex should return true for the string John has a pet dog.
6+
- Your regex petRegex should return false for the string Emma has a pet rock.
7+
- Your regex petRegex should return true for the string Emma has a pet bird.
8+
- Your regex petRegex should return true for the string Liz has a pet cat.
9+
- Your regex petRegex should return false for the string Kara has a pet dolphin.
10+
- Your regex petRegex should return true for the string Alice has a pet fish.
11+
- Your regex petRegex should return false for the string Jimmy has a pet computer.
12+
*/
13+
let petString = "James has a pet cat.";
14+
let petRegex = /dog|cat|bird|fish/; // Changed this line
15+
let result = petRegex.test(petString);
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
Ignore Case While Matching:
3+
Write a regex fccRegex to match freeCodeCamp, no matter its case. Your regex should not match any abbreviations or variations with spaces.
4+
5+
- Your regex should match the string freeCodeCamp
6+
- Your regex should match the string FreeCodeCamp
7+
- Your regex should match the string FreecodeCamp
8+
- Your regex should match the string FreeCodecamp
9+
- Your regex should not match the string Free Code Camp
10+
- Your regex should match the string FreeCOdeCamp
11+
- Your regex should not match the string FCC
12+
- Your regex should match the string FrEeCoDeCamp
13+
- Your regex should match the string FrEeCodECamp
14+
- Your regex should match the string FReeCodeCAmp
15+
*/
16+
let myString = "freeCodeCamp";
17+
let fccRegex = /freeCodeCamp/i; // Changed this line
18+
let result = fccRegex.test(myString);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/*
2+
Extract Matches:
3+
Apply the .match() method to extract the string coding.
4+
5+
- The result should have the string coding
6+
- Your regex codingRegex should search for the string coding
7+
- You should use the .match() method.
8+
*/
9+
let extractStr = "Extract the word 'coding' from this string.";
10+
let codingRegex = /coding/; // Changed this line
11+
let result = extractStr.match(codingRegex); // Changed this line
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
Find More Than the First Match:
3+
Using the regex starRegex, find and extract both Twinkle words from the string twinkleStar.
4+
5+
Note: You can have multiple flags on your regex like /search/gi
6+
7+
- Your regex starRegex should use the global flag g
8+
- Your regex starRegex should use the case-insensitive flag i
9+
- Your match should match both occurrences of the word Twinkle
10+
- Your match result should have two elements in it.
11+
*/
12+
let twinkleStar = "Twinkle, twinkle, little star";
13+
let starRegex = /twinkle/gi; // Changed this line
14+
let result = twinkleStar.match(starRegex); // Changed this line
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
Match Anything with Wildcard Period:
3+
Complete the regex unRegex so that it matches the strings run, sun, fun, pun, nun, and bun. Your regex should use the wildcard character.
4+
5+
- You should use the .test() method.
6+
- You should use the wildcard character in your regex unRegex
7+
- Your regex unRegex should match run in the string Let us go on a run.
8+
- Your regex unRegex should match sun in the string The sun is out today.
9+
- Your regex unRegex should match fun in the string Coding is a lot of fun.
10+
- Your regex unRegex should match pun in the string Seven days without a pun makes one weak.
11+
- Your regex unRegex should match nun in the string One takes a vow to be a nun.
12+
- Your regex unRegex should match bun in the string She got fired from the hot dog stand for putting her hair in a bun.
13+
- Your regex unRegex should not match the string There is a bug in my code.
14+
- Your regex unRegex should not match the string Catch me if you can.
15+
*/
16+
let exampleStr = "Let's have fun with regular expressions!";
17+
let unRegex = /.un/; // Changed this line
18+
let result = unRegex.test(exampleStr);
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
Match Single Character with Multiple Possibilities:
3+
Use a character class with vowels (a, e, i, o, u) in your regex vowelRegex to find all the vowels in the string quoteSample.
4+
5+
Note: Be sure to match both upper- and lowercase vowels.
6+
7+
- You should find all 25 vowels.
8+
- Your regex vowelRegex should use a character class.
9+
- Your regex vowelRegex should use the global flag.
10+
- Your regex vowelRegex should use the case-insensitive flag.
11+
- Your regex should not match any consonants.
12+
*/
13+
let quoteSample = "Beware of bugs in the above code; I have only proved it correct, not tried it.";
14+
let vowelRegex = /[aeiou]/gi; // Changed this line
15+
let result = quoteSample.match(vowelRegex); // Changed this line
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*
2+
Match Letters of the Alphabet:
3+
Match all the letters in the string quoteSample.
4+
5+
Note: Be sure to match both uppercase and lowercase letters.
6+
7+
- Your regex alphabetRegex should match 35 items.
8+
- Your regex alphabetRegex should use the global flag.
9+
- Your regex alphabetRegex should use the case-insensitive flag.
10+
*/
11+
let quoteSample = "The quick brown fox jumps over the lazy dog.";
12+
let alphabetRegex = /[a-z]/gi; // Changed this line
13+
let result = quoteSample.match(alphabetRegex); // Changed this line
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/*
2+
Match Numbers and Letters of the Alphabet:
3+
Create a single regex that matches a range of letters between h and s, and a range of numbers between 2 and 6. Remember to include the appropriate flags in the regex.
4+
5+
- Your regex myRegex should match 17 items.
6+
- Your regex myRegex should use the global flag.
7+
- Your regex myRegex should use the case-insensitive flag.
8+
*/
9+
let quoteSample = "Blueberry 3.141592653s are delicious.";
10+
let myRegex = /[h-s2-6]/gi; // Changed this line
11+
let result = quoteSample.match(myRegex); // Changed this line

0 commit comments

Comments
 (0)