Last active
May 21, 2018 16:28
-
-
Save Frenchcooc/e4e0c192bf1dd21ce5399ef748516298 to your computer and use it in GitHub Desktop.
Easy utilitary to get information from string using regexp
This file contains 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
/** | |
* 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