Skip to content

Instantly share code, notes, and snippets.

@kobaatsu
Last active August 15, 2022 09:58
Show Gist options
  • Save kobaatsu/b3a7d8c64cfe454ba9bd36f03f90fe42 to your computer and use it in GitHub Desktop.
Save kobaatsu/b3a7d8c64cfe454ba9bd36f03f90fe42 to your computer and use it in GitHub Desktop.
正規表現 #js #note
// https://regex101.com/r/gXDhi9/1
isValidImageUrl = (url) => {
const imgReg =
/^(?:(?<scheme>[^:/?#]+):)?(?:\/\/(?<authority>[^/?#]*))?(?<path>[^?#]*\/)?(?<file>[^?#]*\.(?<extension>[Jj][Pp][Ee]?[Gg]|[Pp][Nn][Gg]|[Gg][Ii][Ff]|[Ss][Vv][Gg]|[Ww][Ee][Bb][Pp]))(?:\?(?<query>[^#]*))?(?:#(?<fragment>.*))?$/gm;
return imgReg.test(url);
};
/https?:\/\/[\w/:%#\$&\?\(\)~\.=\+\-]+/;
/https:\/\/(www\.)?(youtube\.com\/watch\?v=|youtu\.be\/)+[\S]{11}/;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment