Skip to content

Instantly share code, notes, and snippets.

@codebubb
Last active April 14, 2023 14:23
Show Gist options
  • Select an option

  • Save codebubb/bb19d7ae24cd41695cb3c5ec3b1155d5 to your computer and use it in GitHub Desktop.

Select an option

Save codebubb/bb19d7ae24cd41695cb3c5ec3b1155d5 to your computer and use it in GitHub Desktop.
Some Regex string testers
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.
Copy link
Copy Markdown

ghost commented Nov 16, 2022

@Flori1234657
Copy link
Copy Markdown

//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