Skip to content

Commit

Permalink
Added practice for regexs
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason011125 committed Mar 9, 2022
1 parent 52f23a7 commit 51ef7d6
Show file tree
Hide file tree
Showing 28 changed files with 87 additions and 0 deletions.
File renamed without changes.
3 changes: 3 additions & 0 deletions Match4OrMore.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
let haStr = "Hazzzzah";
let haRegex = /Haz{4,}ah/; // Change this line
let result = haRegex.test(haStr);
3 changes: 3 additions & 0 deletions MatchOh.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
let ohStr = "Ohhh no";
let ohRegex = /Oh{3,6}\sno/; // Change this line
let result = ohRegex.test(ohStr);
4 changes: 4 additions & 0 deletions RegexToMatchStrings/AlphabetRegex.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
let quoteSample = "The five boxing wizards jump quickly.";
let alphabetRegexV2 = /\wg/; // Change this line
let result = quoteSample.match(alphabetRegexV2).length;
console.log(result)
3 changes: 3 additions & 0 deletions RegexToMatchStrings/CheckUserName.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
let username = "JackOfAllTrades";
let userCheck = /^[a-z][a-z]+[0-9]*$|[a-z][\d][\d]+$/i; // check whether the username start with 2 letters or start with 1 letter and followed by number.
let result = userCheck.test(username);
3 changes: 3 additions & 0 deletions RegexToMatchStrings/CountingWhiteSpace.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
let sample = "Whitespace is important in separating words";
let countWhiteSpace = /\s/g; // Change this line
let result = sample.match(countWhiteSpace);
3 changes: 3 additions & 0 deletions RegexToMatchStrings/FindMultipleMatch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
let twinkleStar = "Twinkle, twinkle, little star";
let starRegex = /twinkle/gi; // Change this line
let result = twinkleStar.match(starRegex); // Change this line
3 changes: 3 additions & 0 deletions RegexToMatchStrings/IgnoreCaseMatch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
let myString = "freeCodeCamp";
let fccRegex = /freeCodeCamp/i; // Change this line
let result = fccRegex.test(myString);
4 changes: 4 additions & 0 deletions RegexToMatchStrings/LazyMatch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
let text = "<h1>Winter is coming</h1>";
let myRegex = /<.*?>/; // Change this line
let result = text.match(myRegex);
console.log(result);
3 changes: 3 additions & 0 deletions RegexToMatchStrings/MatchAllNumberAndLetters.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
let quoteSample = "The five boxing wizards jump quickly.";
let alphabetRegexV2 = /\w/gi; // Change this line
let result = quoteSample.match(alphabetRegexV2).length;
3 changes: 3 additions & 0 deletions RegexToMatchStrings/MatchAlphabet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
let quoteSample = "The quick brown fox jumps over the lazy dog.";
let alphabetRegex = /[a-z]/gi; // Change this line
let result = quoteSample.match(alphabetRegex); // Change this line
3 changes: 3 additions & 0 deletions RegexToMatchStrings/MatchAnythingWithDot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
let exampleStr = "Let's have fun with regular expressions!";
let unRegex = /.un/; // Match anything end with un
let result = unRegex.test(exampleStr);
4 changes: 4 additions & 0 deletions RegexToMatchStrings/MatchBothNumberAndLetter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
let quoteSample = "Blueberry 3.141592653s are delicious.";
let myRegex = /[h-s2-6]/ig; // Change this line
let result = quoteSample.match(myRegex); // Change this line
console.log(result);
3 changes: 3 additions & 0 deletions RegexToMatchStrings/MatchBothVersion.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
let favWord = "favorite";
let favRegex = /favou?rite/; // Change this line
let result = favRegex.test(favWord);
3 changes: 3 additions & 0 deletions RegexToMatchStrings/MatchCharacterMoreThan1Time.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
let difficultSpelling = "Mississippi";
let myRegex = /s+/g; // Change this line
let result = difficultSpelling.match(myRegex);
3 changes: 3 additions & 0 deletions RegexToMatchStrings/MatchExact3Times.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
let repeatNum = "42 42 42";
let reRegex = /^(\d+)(\s)\1\2\1$/; // Change this line
let result = reRegex.test(repeatNum);
3 changes: 3 additions & 0 deletions RegexToMatchStrings/MatchExactNumber.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
let timStr = "Timmmmber";
let timRegex = /Tim{4}ber/; // Change this line
let result = timRegex.test(timStr);
3 changes: 3 additions & 0 deletions RegexToMatchStrings/MatchMethodExample.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
let extractStr = "Extract the word 'coding' from this string.";
let codingRegex = /coding/; // Change this line
let result = extractStr.match(codingRegex); // Change this line
3 changes: 3 additions & 0 deletions RegexToMatchStrings/MatchNonLetterAndLetters.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
let quoteSample = "The five boxing wizards jump quickly.";
let nonAlphabetRegex = /\W/g; // Change this line
let result = quoteSample.match(nonAlphabetRegex).length;
3 changes: 3 additions & 0 deletions RegexToMatchStrings/MatchNonNumber.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
let movieName = "2001: A Space Odyssey";
let noNumRegex = /\D/g; // Change this line
let result = movieName.match(noNumRegex).length;
3 changes: 3 additions & 0 deletions RegexToMatchStrings/MatchNonVowelAndNumbers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
let quoteSample = "3 blind mice.";
let myRegex = /[^aeiou0-9]/gi; // Change this line
let result = quoteSample.match(myRegex); // Change this line
3 changes: 3 additions & 0 deletions RegexToMatchStrings/MatchNonWhiteSpace.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
let sample = "Whitespace is important in separating words";
let countNonWhiteSpace = /\S/g; // Change this line
let result = sample.match(countNonWhiteSpace);
3 changes: 3 additions & 0 deletions RegexToMatchStrings/MatchNumbersAlone.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
let movieName = "2001: A Space Odyssey";
let numRegex = /\d/g; // Change this line
let result = movieName.match(numRegex).length;
4 changes: 4 additions & 0 deletions RegexToMatchStrings/MatchVowelsInString.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
let quoteSample = "Beware of bugs in the above code; I have only proved it correct, not tried it.";
let vowelRegex = /[aeiou]/gi; // Change this line
let result = quoteSample.match(vowelRegex); // Change this line
console.log(result);
4 changes: 4 additions & 0 deletions RegexToMatchStrings/MixGroupingExample.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
let myString = "Eleanor Roosevelt";
let myRegex = /(Franklin|Eleanor).*Roosevelt/; // Change this line
let result = myRegex.test(myString); // Change this line
// After passing the challenge experiment with myString and see how the grouping works
3 changes: 3 additions & 0 deletions RegexToMatchStrings/PassWordCheckExample.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
let sampleWord = "astronaut";
let pwRegex = /(?=\w{6,})(?=\D*\d\d)/; // Change this line
let result = pwRegex.test(sampleWord);
3 changes: 3 additions & 0 deletions RegexToMatchStrings/TrimWhiteSpaceWithRegex.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
let hello = " Hello, World! ";
let wsRegex = /^(\s+)|(\s+)$/g; // Change this line
let result = hello.replace(wsRegex,""); // Change this line
4 changes: 4 additions & 0 deletions RegexToMatchStrings/UseRegexToReplace.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
let str = "one two three";
let fixRegex = /(\w+)\s(\w+)\s(\w+)/; // Change this line
let replaceText = "$3 $2 $1"; // Change this line
let result = str.replace(fixRegex, replaceText);

0 comments on commit 51ef7d6

Please sign in to comment.