Skip to content

Instantly share code, notes, and snippets.

@Frenchcooc
Last active May 21, 2018 16:28
Show Gist options
  • Save Frenchcooc/e4e0c192bf1dd21ce5399ef748516298 to your computer and use it in GitHub Desktop.
Save Frenchcooc/e4e0c192bf1dd21ce5399ef748516298 to your computer and use it in GitHub Desktop.
Easy utilitary to get information from string using regexp
/**
* Simple RegExp capture
*/
function regexp_capture(regexp, data)
{
if (!data)
{ return false; }
var output = (new RegExp(regexp)).exec(data);
if (!output || output.length < 2)
{ return false; }
return output[1];
}
// Demo
let url = "https://www.youtube.com/watch?v=PWgvGjAhvIw"
let videoID = regexp_capture("v=([A-z]+)",url)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment