Skip to content

Instantly share code, notes, and snippets.

@kitz99
Created July 5, 2018 07:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kitz99/874e948ab7fff92fbf0c5bb7d68901dc to your computer and use it in GitHub Desktop.
Save kitz99/874e948ab7fff92fbf0c5bb7d68901dc to your computer and use it in GitHub Desktop.
const data = "This sentence uses word1 and also word2"
// using regex groups to extract word1 and word2
var result = data.match(/^This sentence uses (.*) and also (.*)$/);
const opt1 = resutt[1];
const opt2 = result[2];
// using destructuring
const { 3: opt1, 6: opt2 } = data.split(' ');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment