Last active
April 14, 2023 14:23
-
-
Save codebubb/bb19d7ae24cd41695cb3c5ec3b1155d5 to your computer and use it in GitHub Desktop.
Some Regex string testers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const ex1 = 'The quick brown fox jumped over the lazy dog'; | |
| const ex2 = 'A1B2C3D4E5F6G7H8I9J10'; | |
| const ex3 = 'The salad costs $9.99'; | |
| const ex4 = 'Contact customer support on 0800 300 500'; | |
| const ex5 = 'You can contact me on Twitter @codebubb or james@juniordevelopercentral.com'; | |
| // Exercise 01 | |
| // Using a regex pattern, get the 3 letter words in the ex1 string. | |
| // Exercise 02 | |
| // Using a regex pattern, remove all of the numbers from the ex2 string. | |
| // Exercise 03 | |
| // Using a regex pattern, find the monetary value contained within the ex3 string. | |
| // Exercise 04 | |
| // Using a regex pattern, find the telephone number contained within the ex4 string. | |
| // Exercise 05 | |
| // Using a regex pattern, find the email address contained within the ex5 string. | |
//EX-1
console.log(ex1.match(/^\w+/ig))
//EX-2
console.log(ex2.match(/\D/ig))
//EX-3
console.log(ex3.match(/\W\d[\W]\d+/g))
//EX-4
console.log(ex4.match(/\d/g))
//EX-5
console.log(ex5.match(/@[a-z]+/g)) Until emails start with @ you don't need a big logic to do that
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://gist.github.com/Dashrarth-Sharma/9b31a9d630e997e045cd3b4494a6511e