-
-
Save max8hine/c88034ba17c2abbd7b8f1e8374233e37 to your computer and use it in GitHub Desktop.
Regex
This file contains hidden or 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
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