Skip to content

Instantly share code, notes, and snippets.

@max8hine
Created August 14, 2019 23:42
Show Gist options
  • Save max8hine/c88034ba17c2abbd7b8f1e8374233e37 to your computer and use it in GitHub Desktop.
Save max8hine/c88034ba17c2abbd7b8f1e8374233e37 to your computer and use it in GitHub Desktop.
Regex
var link = 'http://www.google.com/uploads/art/art_max_156575641388.0.png'
var parsingUrl = link.match(/\.([^.]*?)(?=\?|#|$)/)
/* [ '.png', 'png', index: 56, input: 'http://www.google.com/uploads/art/art_max_156575641388.0.png', groups: undefined ] */
var isPath = (/\.(jpg|jpeg|png)$/i).test(link)
/* true */
trimmedArtist = artist
.trim()
.replace(/[^a-zA-Z0-9]+/g, " ") // remove special characters
.replace(/[ \t]+$/g, "") // remove trailing whitespace
.replace(/\s+/g, "_"); // replace whitespace to '_'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment