Skip to content

Instantly share code, notes, and snippets.

@mr21
Last active April 14, 2017 03:08
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 mr21/890248860c39016cb80dd72c420daed6 to your computer and use it in GitHub Desktop.
Save mr21/890248860c39016cb80dd72c420daed6 to your computer and use it in GitHub Desktop.
JavaScript: some regexp
/[^/]*$/.exec( "https://asd.x/file.wav" )[ 0 ]; // "file.wav"
/[^/]*$/.exec( "file.wav" )[ 0 ]; // "file.wav"
/[^/]*$/.exec( "qwe.rty/" )[ 0 ]; // ""
/(?:([^/]*)\.([a-zA-Z\d]*))?$/.exec( "" ); // [ "", undefined, undefined ]
/(?:([^/]*)\.([a-zA-Z\d]*))?$/.exec( ".wav" ); // [ ".wav", "", "wav" ]
/(?:([^/]*)\.([a-zA-Z\d]*))?$/.exec( "://a.b/q/a.b.mp3" ); // [ "a.b.mp3", "a.b", "mp3" ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment