JS Regular Expressions Exercises 1
By Ifeanyi Omeata

Hi, I am a Software Developer of 3-4 years specialising in React, Javascript, Node, NextJS, Express, Python, Django, Fast API, SQL and a few other technology stack, with a good background in Networking and Cloud Infrastructure. I am working to become a DevOps Solutions Engineer and happily married to my long time girlfriend.
Task 1 -
const greeting = "Hello World";
Using Regular expressions (Regex), find out if the string "Hello" is found in greeting.
/*
Using Regular expressions (Regex), find out if the string "Hello" is found in greeting.
*/
const greeting = "Hello World";
const isTrue = /Hello/.test(greeting);
console.log(isTrue);

Task 2 -
const greeting = "Hello, is that a cat?";
Using Regex, find out if any of the following: (dog,cat,mice,bird) is in the string greeting.
/*
Using Regex, find out if any of the following: (dog,cat,mice,bird) is in the string greeting.
*/
const greeting = "Hello, is that a cat?";
const isTrue = /dog|cat|mice|bird/.test(greeting);
console.log(isTrue);

Task 3 -
const greeting = "Hello, is that a cat?";
Using Regex, ensure that "hello" returns true when searched for in the string greeting.
/*
Using Regex, ensure that "hello" returns true when searched for in the string greeting.
*/
const greeting = "Hello, is that a cat?";
isTrue = /hello/i.test(greeting)
console.log(isTrue)

Task 4 -
const students = "Andrew, Mary, Shade, Bob, Peter, Mike";
const bestStudent = "Peter";
Using Regex, find out if bestStudent is found in students and log out the name of the student.
/*
Using Regex, find out if bestStudent is found in students and log out the name of the student.
*/
const students = "Andrew, Mary, Shade, Bob, Peter, Mike";
const bestStudent = /Peter/;
const student = students.match(bestStudent);
console.log(student);
console.log(student[0]);

Task 5 -
const students = "Andrew, Mary, Shade, Andrew, Peter, Andrew";
const bestStudent = "Andrew";
Using Regex, log out all the values of occurences of bestStudent in the students string.
/*
Using Regex, log out all the values of occurences of bestStudent in the students string.
*/
const students = "Andrew, Mary, Shade, Andrew, Peter, Andrew";
const bestStudent = /Andrew/g;
result = students.match(bestStudent);
console.log(result)

Task 6 -
const poem = "Twinkle, twinkle, twinKLE, little star";
let word = "twinkle";
Using Regex, log out all the values of occurences (not Case-Sensitive) of word in the poem string.
/*
Using Regex, log out all the values of occurences (not Case-Sensitive) of word in the poem string.
*/
const poem = "Twinkle, twinkle, twinKLE, little star";
let word = /twinkle/ig;
let result = poem.match(word);
console.log(result);

Task 7 -
const myString = "ado, edu, obu, edi, edu ";
Using Regex, log out all occurances of strings in myString that starts with ed-.
/*
Using Regex, log out all occurances of strings in myString that starts with ed-.
*/
const myString = "ado, edu, obu, edi, edu ";
let word = /ed./g;
let result = myString.match(word);
console.log(result);

Task 8 -
const myString = "big, buy, bug, but, bag";
Using Regex, log out all occurances of strings (not case sensitive) in myString that has this syntax:
b-(aeiou)-g
First character: b
Second character: Any of these ('a' or 'e' or 'i' or 'o' or 'u')
Third character: g
// Task 8 -
// const myString = "big, buy, bug, but, bag";
// Using Regex, log out all occurances of strings (not case sensitive) in myString that has this syntax:
// b-(aeiou)-g
// First character: b
// Second character: Any of these ('a' or 'e' or 'i' or 'o' or 'u')
// Third character: g
const myString = "big, buy, bug, but, bag";
const str = /b[aeiou]g/ig;
const result = myString.match(str)
console.log(result)

#End
Hope you enjoyed this! :) Follow me for more contents...
Get in Touch:
www.ifeanyiomeata.com
contact@ifeanyiomeata.com
Youtube: https://www.youtube.com/c/IfeanyiOmeata
Linkedin: https://www.linkedin.com/in/omeatai/
Twitter: https://twitter.com/iomeata
Github: https://github.com/omeatai/
Stackoverflow: https://stackoverflow.com/users/2689166/omeatai
Hashnode: https://hashnode.com/@omeatai
Medium: https://medium.com/@omeatai
© 2021**






